Re: [whatwg/streams] pipeTo should return a cancelable promise (#446)

I'd like to confirm if I understand the example by Jake in the OP correctly.

The `merge` function creates an identity stream to represent a readable stream producing the result of merging the provided readable streams. Right?

When `stream` is cancelled, the identity stream needs to propagate the cancellation to the writable side. So, we need to design the identity stream to allow that.

`pipeTo()` can already notify the caller of any error on `dest`. It can be caught to cancel the remaining not-yet-piped readable streams.

```
function merge(readables) {
  // Configure to propagate cancellation on the readable side to the writable side
  const id = ...;
  function pipeNext() {
    if (readables.length === 0) {
      return;
    }
    const rs = readables.shift();
    rs.pipeTo(id.writable, {preventClose: readables.length === 0}).then(() => {
      pipeNext();
    }, e => {
      for (rs of readables) {
        rs.cancel(e);
      }
    });
  }
  pipeNext();
  return id.readable;
}
```

IIRC, here cancelling an ongoing `pipeTo()` isn't needed anywhere. So, I guess I'm misunderstanding the OP.

-- 
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/446#issuecomment-303037359

Received on Monday, 22 May 2017 08:43:49 UTC