Wrap a WebSocket-like object as an async iterable of message events.
Supports both browser-style WebSocket (addEventListener/removeEventListener)
and Node.js EventEmitter-style (on/off).
Returns cleanly when the socket emits 'close'.
Throws when the socket emits 'error'. Any messages received before the
error are yielded first; the error is thrown when the consumer tries to
read the next message. Consumers should wrap the for-await loop in try/catch
to distinguish clean close from connection failure (and decide whether to
reconnect).
Wrap a WebSocket-like object as an async iterable of message events.
Supports both browser-style WebSocket (addEventListener/removeEventListener) and Node.js EventEmitter-style (on/off).