stream-chain icon indicating copy to clipboard operation
stream-chain copied to clipboard

ability to provide "RedableFunction" as a StreamItem for input

Open mannharleen opened this issue 3 years ago • 1 comments

To create a chain with input as a readable stream, the first element of the constructor's streamItem[] can be a readable stream. However, it would be great to have the ability to provide a ReadableFunction just like we allows a TransformFunction.

ReadableFunction then essentially returns the readable stream.

Use case: this is helpful to work with readable streams where an async operation is involved e.g. pg database.

Expectation: The following should work

new Chain([
async() => {
  let client = new pg.client(...)
  await client.connect()
  return client.query(new QueryStream(...)) // a Promise<ReadableStream>
}, 
x => {console.log(x)}
]

mannharleen avatar Oct 20 '22 12:10 mannharleen

Am I correct in assuming that you want to have a function that returns a stream, which should feed the rest of the pipe?

If that's the correct assumption, why not use something like that:

async function abc () { /* ... */ return stream; }

const pipeline = new Chain([ /* ... */ ]);

(await abc()).pipe(pipeline);

Whatever chain produces is just a regular stream, which can be used normally.

uhop avatar Apr 26 '23 22:04 uhop

Closing for inactivity.

uhop avatar Jun 13 '24 04:06 uhop