- From: Mattias Buelens <notifications@github.com>
- Date: Thu, 29 Jan 2026 22:52:38 -0800
- To: whatwg/streams <streams@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/streams/issues/1359/3822162831@github.com>
MattiasBuelens left a comment (whatwg/streams#1359)
> One possible refinement I’ve been considering is to drop the “safe” framing entirely and instead make the stream’s completion state observable.
>
> Concretely, something along these lines:
>
> ```js
> const resolvers = ReadableStream.withResolvers();
> const { stream, enqueue, close, error } = resolvers;
> ```
Or you could group those methods in a single object and perhaps... call it a controller? 😄
```javascript
const { stream, controller } = ReadableStream.withController();
controller.enqueue("a");
controller.close();
```
> ```js
> resolvers.completed;
> // → true if close() or error() has already been called, otherwise false
> ```
>
> Here, `completed` would be exposed as a getter rather than a plain boolean value. If it were a data property, destructuring would snapshot the value and wouldn’t reflect subsequent state changes, which seems error-prone. A getter allows producers to deliberately check the current completion state without changing any existing semantics.
>
> This approach wouldn’t suppress exceptions from `enqueue()`, `close()`, or `error()`, nor would it alter backpressure behavior. Those operations would still fail fast as they do today. The goal is simply to provide an explicit, opt-in way for producers to observe completion and avoid late enqueues intentionally, rather than relying on try/catch.
>
> Exposing dynamic internal state via getters is also consistent with existing Streams APIs such as `stream.locked` or `controller.desiredSize`, which makes this feel like a natural extension rather than a special case.
This could be interesting, but we can then add it to the existing `ReadableStreamDefaultController` API instead. Something like:
* `controller.state`
* `controller.closed`
* ...
--
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/issues/1359#issuecomment-3822162831
You are receiving this because you are subscribed to this thread.
Message ID: <whatwg/streams/issues/1359/3822162831@github.com>
Received on Friday, 30 January 2026 06:52:42 UTC