Re: [whatwg/streams] ReadableStream.prototype.pipeline(...) (Issue #1184)

This is fairly easy to do in user-land. You can use the fact that `pipeThrough()` accepts a `{ readable, writable }` pair, where the two streams don't necessarily have to come from the same `TransformStream`:
```javascript
function pipeline(...transforms) {
  if (transforms.length === 0) return new TransformStream();
  let { readable, writable } = transforms[0];
  for (let i = 1; i < transforms.length; i++) {
    readable = readable.pipeThrough(transforms[i]);
  }
  return { readable, writable };
}

const transformChain = pipeline(transform1, transform2, transform3);
const readable = source.pipeThrough(transformChain, options);
```
This composes perfectly: `pipeline(pipeline(t1, t2), pipeline(t3, t4))` is equivalent to `pipeline(t1, t2, t3, t4)`. 🙂

I think, for now, it's fine to keep this in user land. If it gets more wide-spread adoption, we may consider standardizing it.

-- 
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/1184#issuecomment-964502855

Received on Tuesday, 9 November 2021 20:17:48 UTC