paldepind / flyd

The minimalistic but powerful, modular, functional reactive programming library in JavaScript.
MIT License
1.56k stars 84 forks source link

from Node stream #223

Open JamesRamm opened 2 years ago

JamesRamm commented 2 years ago

Hi I am looking at making a little utility for creating a stream from a nodeJS readable stream , this will bring all the nice monadic interfaces of flyd (using map, chain etc is much simpler and clearer than writing transform streams...).

I am thinking of something like this:

function fromReadable(readable) {
  const s = flyd.stream();
  readable.on('data', s);
  readable.on('end',  () => s.end(true));
}

Do you forsee any issues with this? Have I lost backpressure? Any ideas on how to handle errors?

StreetStrider commented 1 year ago

Have I lost backpressure?

Most likely. flyd is push. Readable is pull. Implementing backpressure in push world requires some careful actions. You need to pass signals back by the pipe which is against push idea.

If you want something nice and simple like flyd but for data consuming, I think your first stop would be callbags. I think they have backpressure implemented as a specific operator and you can implement your own, bc callbag has API to signal back.

The bigger alternatives are most.js and Highland (both not being actively developed).

nordfjord commented 1 year ago

I'll add IxJS to the list of alternatives when dealing with async iterables