- From: Adam Rice <notifications@github.com>
- Date: Fri, 22 Nov 2024 00:15:53 -0800
- To: whatwg/streams <streams@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Friday, 22 November 2024 08:15:57 UTC
I think the motivation for this behaviour was that the user shouldn't be punished for something out of their control. In your example, `controller.error()` is called from within `write()` but its main purpose is to signal errors that happen asynchronously. The following is an example of the intended use case:
```
const stream = new WritableStream({
start(controller) {
this.handle = await openFile(file);
this.handle.onerror = evt => { controller.error(new Error(evt.reason); };
},
write(chunk) {
await this.handle.write(chunk);
},
});
```
If the `onerror` event fires while a write is in progress, we don't actually know whether the write succeeded or failed (but if we also get a promise rejection then that will be returned from `writer.write()`). So returning a rejection from `writer.write()` would not be actionable.
--
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/issues/1332#issuecomment-2493136732
You are receiving this because you are subscribed to this thread.
Message ID: <whatwg/streams/issues/1332/2493136732@github.com>
Received on Friday, 22 November 2024 08:15:57 UTC