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

readArray stream must be used on the same `tick` #60

Closed
treet opened this Issue May 1, 2014 · 4 comments

Comments

Projects
None yet
3 participants
@treet

treet commented May 1, 2014

es.readArray([1,2,3]).on('data', function (n) { console.log(n); });

works as expected while

var stream = es.readArray([1,2,3]);
process.nextTick(function () {
   stream.on('data', function (n) { console.log(n); });
});

does not work (nothing is printed)

This happens since the contents of the array is emitted to the stream on first stream.resume in a while loop (https://github.com/dominictarr/event-stream/blob/master/index.js#L108), which means delaying the use of the stream a tick makes it unusable.

Is this intended behaviour?

@dominictarr

This comment has been minimized.

Owner

dominictarr commented May 2, 2014

yes - most stream1 stream work like this.
however, if you use streams2 this will work.

@treet

This comment has been minimized.

treet commented May 4, 2014

Thanks! I didn't notice that event-stream creates 0.8 streams and not 0.10 streams. Creating the stream like this makes everything work as expected:

var s = new stream.Readable({ objectMode: true }).wrap(es.readArray([1,2,3]));

@treet treet closed this May 4, 2014

@sukima

This comment has been minimized.

Contributor

sukima commented Nov 8, 2014

This should be in the README! Lost 30 minutes till I found this closed issue. Thank you for the info though it helped a lot!

@dominictarr

This comment has been minimized.

Owner

dominictarr commented Nov 8, 2014

@sukima make a pull request if you like

sukima added a commit to sukima/event-stream that referenced this issue Nov 10, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment