Emit 'error' synchronously
Emit 'error' synchronously

Emitting the error asyncronously makes it impossible for users to handle 'close' and 'error' together easily.

If I want to know about 'close', plus whether there's an error, then it's good that 'error' fires first.

Basically, I know that if I get an 'error' event, the socket is closed and there was an error.

If I get a 'close' event (and haven't got an 'error' yet), then I know the socket is closed and there was not an error.

But what am I supposed to do if 'error' is emitted on the next tick?

Then when I get a 'close' event, I don't know if there's been an error or not. And I can't do any cleanup or respond to the 'close' yet since there could be an 'error' coming on the next tick.

Am I missing something here?

feross/simple-websocket