bustle / bluestream

A collection of streams that work well with promises (through, map, reduce). Think Through2 with promises
MIT License
103 stars 5 forks source link

A way to combine streams #14

Open reconbot opened 7 years ago

reconbot commented 7 years ago

A way to combine streams is needed. It's one of those things that should be easy to do.

The following wont work right.

const oldUsers = new OldUserStream()
const newUsers = new NewUserStream()
const countUsers = new CountUserStream()

oldUsers.pipe(countUsers)
newUsers.pipe(countUsers)

countUsers.on('end', letEveryoneKnowWereDone)

If we have more old users than new users the new users stream will end and end the count users pipe. Pipe takes an option to stop propagating the close event but then you have to manually listen for both close events and then call .end() on the destination stream. That's annoying.

The multistream package solves this by piping one stream than another. But we often want to do these operations concurrently. So merge-stream fits that bill.

Maybe this should be built into pipe? However if that's the case we need to ensure the inverse works too. (multiplexing).

bluestream.pipe([oldUsers, newUsers], buildEmails, [sendEmails, saveEmails])

I wan to keep researching prior art.

CodeMan99 commented 6 years ago

Some other options:

I've personally used combined-stream, but also wonder if I should use something else.

reconbot commented 6 years ago

merge2 works for other projects i've used