Re: [whatwg/streams] Calling close() on TransformStreamDefaultController should relieve backpressure (#774)

> 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