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

event-stream.readable overcalls async function #2

Closed
fireflymantis opened this Issue Oct 31, 2011 · 4 comments

Comments

Projects
None yet
2 participants
@fireflymantis

fireflymantis commented Oct 31, 2011

Running the following:

var es = require("event-stream");

var source = es.readable(function(count, cb){
  setTimeout(function(){
    cb(null, {ok: true, n: count});
  }, 1000);
});

var destination = es.map(function(data, cb){
  console.info(data); cb();
});

es.connect(source, destination);

I think the above should, once a second, write out a new line looking something like {ok: true, n: 1} where n increments every time. Instead it works correctly momentarily, but begins to 'double up' with every call. It will print n = 1, then two lines n = 2, 3. Followed with four lines, n = 4, 5, 6, 7, then eight, sixteen, etc etc.

I looked into the event-stream index.js file and I'm having some trouble tracking down why this behavior is occurring.. It looks like the .readable(fn) function has an embedded get() method which gets passed to the function passed into the original call, kicking off the next cycle... That is, I'm not quite sure how get() or func() is being called twice.

@dominictarr

This comment has been minimized.

Owner

dominictarr commented Oct 31, 2011

you are right. I'm gonna test this now.

@dominictarr dominictarr reopened this Oct 31, 2011

@dominictarr

This comment has been minimized.

Owner

dominictarr commented Nov 1, 2011

I've confirmed this issue.

okay, I figured it out, it's calling get again in resume. which is happening when map emits 'drain'...
I think that might be wrong, that drain should only be emitted if the stream is paused.

but also, readable should not allow multiple read calls at once.

@dominictarr

This comment has been minimized.

Owner

dominictarr commented Nov 1, 2011

okay, this issue is fixed on 0.5.2

@dominictarr dominictarr closed this Nov 1, 2011

@dominictarr

This comment has been minimized.

Owner

dominictarr commented Nov 1, 2011

okay, I fixed the issue with map as well, in 0.5.3

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