- From: Adam Rice <notifications@github.com>
- Date: Tue, 22 Aug 2017 22:22:08 -0700
- To: whatwg/streams <streams@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Wednesday, 23 August 2017 05:22:29 UTC
> If you'll indulge me, I'm kind of unclear on the semantics of a transform controller's close().
Me too.
What I'm imagining is that you already have code to discard chunks you aren't interested in. For example:
```javascript
new TransformStream({
start() {
this.sawPrime = false;
},
transform(chunk, controller) {
if (this.sawPrime) {
return;
}
controller.enqueue(chunk);
if (isPrime(chunk)) {
controller.close();
this.sawPrime = true;
}
}
});
```
In this case `controller.close()` is mostly just an optimisation which allows downstream consumers to complete sooner. However, it makes an important semantic difference when the data source is infinite.
An alternative is that `controller.close()` also tells the TransformStream not to call `transform()` or `flush()` any more. I resisted this idea because it seems too "magical", but on second thought it follows naturally from backpressure being relieved.
--
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/774#issuecomment-324224216
Received on Wednesday, 23 August 2017 05:22:29 UTC