Skip to content
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

take(x) 'takes' nothing when emitted exactly x elements #14

Open
salty-horse opened this issue Jan 24, 2012 · 4 comments
Open

take(x) 'takes' nothing when emitted exactly x elements #14

salty-horse opened this issue Jan 24, 2012 · 4 comments

Comments

@salty-horse
Copy link
Contributor

This is a modified example from the readme.txt:

var Lazy = require('lazy');

var lazy = new Lazy;
lazy
  .take(4)
  .join(function (xs) {
    console.log(xs);
  });

// OK when there are five elements. Prints nothing when there are 4
[1,2,3,4].forEach(function (x) {
  lazy.emit('data', x);
});
@pkrumins
Copy link
Owner

I wonder if it's because you never sent 'end' event?

@salty-horse
Copy link
Contributor Author

lazy.emit('end') after the 4 'data' emits doesn't seem to help.

Frankly, I'm new to node and its conventions, and the Lazy documentation seems to assume some background knowledge.
If you don't think it's a bug, maybe you could clarify how Lazy behaves with events?

@pkrumins
Copy link
Owner

It's a bug then! I'm gonna fix it.

re events: basically lazy eats 'data' events and terminates processing when it receives 'end' event.

@salty-horse
Copy link
Contributor Author

Correction: emit('end') works. Sorry :/ (I probably forgot to save the file before testing)

Just to understand, why does take(x) have to wait for an 'end' if it already received x elements?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants