Does node.js support yield?

Paul Tarjan picture Paul Tarjan · Nov 8, 2010 · Viewed 19.6k times · Source

Is there any way to get generators into node.js?

I'm currently faking them with callbacks, but I have to remember to check the response of the callback inside of my generator function which creates a lot of if (callback(arg) === false) return;

I want something like in python:

for p in primes():
  if p > 100: break
  do_something(p)

which I'm doing in node like this:

primes(function(p) {
  if (p > 100) return false;
  do_something(p)
});

Maybe something like coffeescript could help?