[whatwg/streams] A guide for wrapping a bidirectional transport? (#1032)

Splitting a bidirectional transport into a readable and writable side via a source and a sink is fine and simple... up until the point where one wonders on what needs to be cancelled/aborted/closed/errored when and where. I've read through the spec but I still couldn't figure out what needs to be done where and am still struggling.

Consider having a WebSocket-like transport where the readable and writable side operate separately but only after the transport has been started and only until it has been closed or it errored. What I'm missing is a guide that goes through each of these cases:

What signals need to be propagated to source and sink when...

* a bidirectional transport closes normally,
* a bidirectional transport closes unexpectedly,
* a bidirectional transport errors (I think this is very similar to *closing unexpectedly* but I wanted to mention it nonetheless since WebSocket has a separate event for that).

What signal needs to be propagated to the bidirectional transport (and thus potentially implicitly to the sink) when...

* the source is being cancelled (and what do we need to wait for in that method).

What signal needs to be propagated to the bidirectional transport (and thus potentially implicitly to the source) when...

* the sink is being closed (and what do we need to wait for in that method),
* the sink is being aborted (and what do we need to wait for in that method).

Does this cover all cases?

---

For wrapping an event-based WebSocket, these are my guesses and **please correct me if I'm wrong**:

What signals need to be propagated to source and sink when...

* a bidirectional transport closes normally: *Close the source's controller if not already closed (I've wrapped it in a `try/catch` - please tell me if this is correct). Error the sink's controller.*
* a bidirectional transport closes unexpectedly: *Error the source's controller. Error the sink's controller.*
* a bidirectional transport errors: *Error the source's controller. Error the sink's controller.*

What signal needs to be propagated to the bidirectional transport (and thus potentially implicitly to the sink) when...

* the source is being cancelled (and what do we need to wait for in that method): *Close the bidirectional transport (and wait until it closed - resolve if it closed cleanly, otherwise reject). This will implicitly error the sink.*

What signal needs to be propagated to the bidirectional transport (and thus potentially implicitly to the source) when...

* the sink is being closed (and what do we need to wait for in that method): *Close the bidirectional transport (and wait until it is closed - resolve if it closed cleanly, otherwise reject). This will implicitly close or error the source.*
* the sink is being aborted (and what do we need to wait for in that method): *Close the bidirectional transport (and resolve immediately). This will eventually implicitly close or error the source.*

Is this correct and does this cover all potential side effects?

-- 
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/1032

Received on Tuesday, 17 March 2020 21:20:19 UTC