-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fromNodeStream #178
Comments
I didn't work with node streams yet (I do frontend mostly), but as far as I understand they are a bit different from event streams, because they represent streams of data. I'm not yet sure how well data streams and event streams fit together. Rx has implementation of similar method (methods?) in https://github.com/Reactive-Extensions/rx-node , perhaps we could borrow ideas from there. |
Yeah it only makes sense for object mode: https://nodejs.org/api/stream.html#stream_object_mode For example lots of libs have object streams, like knex for postgres. http://knexjs.org/#Streams-stream It's very similar to // interop for node event emitter
Kefir.fromEventEmitter(emitter, { value: "data", end: "end" })
observable.toEventEmitter({ value: "data", end: "finish" })
// maybe node stream helper
Kefir.fromReadableStream(nodeStream) Or maybe just one or the other? |
I was just typing up a test case before I found this issue. For my use, the import * as Kefir from 'kefir'
import { Readable } from 'stream'
const nodeStream = new Readable()
const kefirStream = Kefir.fromEvents(nodeStream, 'data')
kefirStream.onValue(data => console.log('data', data))
kefirStream.onEnd(() => console.log('end (kefir callback)')) // <-- never runs
nodeStream.on('end', () => console.log('end (node callback)')) // <-- does run
nodeStream.push('some data', 'utf8')
nodeStream.push(null) // signals end of stream In my view, data from a stream is just an event with a I would like to request one of the following enhancements:
Edit: Oh, I see that @aj0strow already submitted a pull request that does just what I want! Please consider my comment to be a vote in favor of #179 . |
Hm, I didn't realize fromEvents can be used to create stream from a node stream. That's cool. Making it end shouldn't be a problem, we can use takeUntilBy: const kefirStream = Kefir.fromEvents(nodeStream, 'data')
.takeUntilBy(Kefir.fromEvents(nodeStream, 'end')) @hallettj will this work for you? |
Yes, that does look good. I had not thought of using
|
Like
fromNodeCallback
andfromPromise
.It's nice to lift node streams into kefir streams. When a stream is in object mode, it's basically a kefir observable anyway with data, error, and end events.
I'm lifting node database streams in a project, so maybe others want it too?
The text was updated successfully, but these errors were encountered: