[whatwg/streams] WebSocket example bug & questions (#1031)

1. I don't think [this](https://streams.spec.whatwg.org/#example-both) WebSocket example would work as expected. The `onclose` event handler is set by both the source and the sink which obviously can't work.

2. I'm confused on why the `onclose` event handler is set to `null` for the `WebSocketSink`. For what purpose is this being done?

```js
this._ws.onclose = () => controller.error(new Error("The server closed the connection unexpectedly!"));
this._ws.addEventListener("error", () => {
  controller.error(new Error("The WebSocket errored!"));
  this._ws.onclose = null;
});
```

3. Is it necessary for the `WebSocketSink` to wait until the `close` event has been fired in both the `close` and the `abort` method? Why would you need to wait for `close` for the `abort` case?

```js
close() {
  return this._closeWS(1000);
}

abort(reason) {
  return this._closeWS(4000, reason && reason.message);
}
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/issues/1031

Received on Tuesday, 17 March 2020 20:38:27 UTC