kefirjs / kefir

A Reactive Programming library for JavaScript
https://kefirjs.github.io/kefir/
MIT License
1.87k stars 97 forks source link

Kefir.stream question #112

Closed myndzi closed 9 years ago

myndzi commented 9 years ago

I was writing a shim for Node streams (I feel like this should be in the library anyway?) and ran into a question about the behavior of Kefir.stream().

It seems as though, if you have multiple items from a source that you can emit, the only way to "correctly" do it is to wait a tick for each item so that unsubscribe can be called if necessary. This seems wasteful and slow. Am I missing something?

What about returning a value from emitter.emit() to let you know when to stop pushing data, as Node does with writable streams? This would allow you to synchronously produce any number of items for your stream but still consume them lazily.

myndzi commented 9 years ago

Actually.. it seems it returns true or false, correlated with this very thing. Maybe add to the docs? Is this something that can be relied on?

myndzi commented 9 years ago

Well, I made this: https://www.npmjs.com/package/kefir-node-stream

Streams2 only, but I think it's pretty thorough.

rpominov commented 9 years ago

Yes, emitter.emit() returns a boolean representing whether connected stream is still active. You can rely on that behavior. It's undocumented because still a subject to change, but most likely will stay.

myndzi commented 9 years ago

That makes sense. Thanks.