- From: Adam Rice <notifications@github.com>
- Date: Tue, 24 Apr 2018 00:29:48 -0700
- To: whatwg/streams <streams@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/streams/issues/244/383831989@github.com>
I had a discussion with @yutakahirano about transferring strategies. He proposed the mental model of a transfer consisting of creating a special kind of TransformStream with one leg in the source context and one leg in the destination context. In the destination context you receive one of these legs directly from the MessageEvent, and in the source context the leg is piped to/from the source stream. I think this model is very helpful. We talked about various ways of attaching a strategy to a WritableStream after it had arrived in the destination context, for example with an `attachStrategy()` method. This would enable (2)'s `transfer()` function to be used. However, the `attachStrategy()` method could only be used when the queue is empty (because otherwise it changes the meaning of queueTotalSize, which is bad). We discussed changing `postMessage()` to be able to specify what the strategy would be on the destination side, but it doesn't really fit into the API. I brought up the issue that `write(chunk)` should perform the transfer synchronously, ie. ```javascript const chunk = new ArrayBuffer(10); writer.write(chunk); console.log(chunk.byteLength); ``` should log `0`. The reasoning behind this is that if the chunk was transferred asynchronously at some later time it would be confusing and error-prone. This means the chunk needs to be cloned into the target thread immediately. However, something still needs to be queued on the sending side in order for backpressure to work properly. I think we need some kind of placeholder that represents the chunk in the queue on the sending side until the chunk is read on the receiving side. We concluded that if we do not have `transfer()` as part of the strategy, then the best way to customise the strategy in the transferred stream is just to put a TransformStream in front of it with the desired strategy. We also discussed what happens if you try to transfer locked streams. Ideally `postMessage()` would throw. Maybe this also applies if `IsDisturbed()` is true? -- 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/244#issuecomment-383831989
Received on Tuesday, 24 April 2018 07:30:12 UTC