-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reset for TransformStream (and WritableStream?) #1026
Comments
I wanted to add that, like with flush (#960), reset is used as a barrier in WebCodecs and it is useful to notify on the output side when the reset has completed. It can be useful to attach metadata to a reset, but we can also queue a followup (passthrough) message for both of these purposes. |
Until now, what we've been doing is to abort the pipe and then re-create it with a new source: const controller = new AbortController();
const sink = new WritableStream({ ... });
let currentPipe = Promise.resolve();
async function setSource(source) {
controller.abort();
controller = new AbortController();
await currentPipe; // wait for the sink to become unlocked
currentPipe = source
.pipeThrough(transform())
.pipeTo(sink, { signal: controller.signal, preventAbort: true })
.catch(() => {});
} This will properly discard any queued chunks. However, we need to re-create all transform streams between the A
If a Perhaps it could help to make
Still, all of this relies on the transformer actually implementing the Does that mean that you can only reset a transform stream that actually implements |
For WebCodecs, we do not need an abort signal. There is a lot of internal state, but chunks are not processed one-by-one. I would imagine that a Transformer that does not implement reset would instead flush, whatever that means. |
With the current semantics, we call A developer can thus use new TransformStream({
start(controller) {
this.worker = new Worker("my-worker.js");
this.worker.onmessage = (event) => {
controller.enqueue(event.data);
};
},
transform(chunk) {
this.worker.postMessage(chunk);
},
flush() {
this.worker.terminate();
}
}); This transform stream uses With the proposed semantics of Now, |
This seems to tie in to previous discussions about a "finally"; see e.g. #636. |
I mean flush as in #960. |
Ah, that does make more sense. 😅 I'm still a bit hesitant though. The way I understand the proposed However, with I'm also not sure whether "call
...Or I might be understanding |
One way forward would be if leaving This seems to be sufficiently difficult and controversial that we won't get to it soon. |
It's not sufficient for one transform stream to support That reminds me:
Agreed, let's not rush this. 👍 For now, developers can abort and re-create their pipe chain if they need to "reset" it. It's not pretty, but it works. |
We currently expect that users of WebCodecs will be writing new streams code. Given that, one simple solution that is acceptable to us would be for the default implementation of reset() to abort the stream. |
On seek, WebCodecs would like to be able to throw away all existing data in the decoder so that they don't display any more frames from before the seek point.
It's easy enough to reset the decoder itself, but there still may be data queued in the writable side of the transform which we need to get rid of. There doesn't seem to be a clean way to do this at the moment.
I tentatively propose a
reset()
method for TransformStream which throws away any queued chunks. This might delegate to abstract operations on ReadableStream and WritableStream which do the actual queue reset.It would probably be useful to have an optional
reset()
method on the underlying transformer. This would have unusual semantics that it could be called while a transform is in progress.reset()
might also be useful for WritableStream although I don't have a specific use case. It might even be useful for ReadableStream but I'm even further from having a use case for that.The text was updated successfully, but these errors were encountered: