Description
hello guys.
the function once
of nodejs v12 LTS makes different behaviors between EventEmitter or EventTarget. REF
This method is intentionally generic and works with the web platform EventTarget interface, which has no special 'error' event semantics and does not listen to the 'error' event.
once
makes judgement about whether an emitter is an EventEmitter or an EventTarget according to whether emitter.addEventListener
is a function. REF
since WebSocket implements addEventListener
in
Line 22 in 535c556
once
will misjudge the emitter to be an EventTarget and it will not listen to error
event. thus, users cannot do:
async function connect(){
ws = new WebSocket('xxx');
await once(ws, 'open');
}
this will be waiting forever if it fails to connect.
since it's said in docs that
This class represents a WebSocket server. It extends the EventEmitter.
, this will mislead users.
but this problem does not exist with nodejs v14, because nodejs v14 makes that judgement via whether emitter.on
is a function. REF
i don't think it's a bug, but it'd be better if this problem should be warning in docs