
Let’s get serious about ES6 generator functions - jamesgpearce
http://facebook.github.io/regenerator/
======
eldude
Good stuff. This will come in handy if node.js 0.12 takes much longer.

Watching the use of generators in JavaScript and especially node.js is going
to be very exciting over the coming years. We're excited at LinkedIn because
we write a lot of node.js, and control flow is always being discussed: step,
async, stepup, promises, and async generators look to solve a lot of that.

Also, checkout the AGen formal spec[1] for asynchronous generators. Raynos and
I put it together recently to encourage interoperability between async
generator solutions, and we're both using it in personal projects.[2]

[1] [https://github.com/AsynchronousGenerators/agen-
spec](https://github.com/AsynchronousGenerators/agen-spec)

[2] [https://github.com/Raynos/gens](https://github.com/Raynos/gens)

~~~
bnjmn
Thanks for the links! I hope regenerator can make those projects work in
environments beyond node.js.

------
bnjmn
Primary author here. Ask me anything!

~~~
PilateDeGuerre
Why is there not a like button, send button, or facebook comments anywhere on
the announcement page?

~~~
bnjmn
Done! Thanks!
[https://github.com/facebook/regenerator/commit/fe42c74a486fb...](https://github.com/facebook/regenerator/commit/fe42c74a486fbe7fa1aac73d41a9d852939083a1)

~~~
PilateDeGuerre
Awwww shucks. I was being cheeky and now your response has disarmed my
cynicism. I'm naked.

------
shtylman
You should make a browserify transform ([https://github.com/substack/node-
browserify](https://github.com/substack/node-browserify)) so that it can
easily be put into a pipeline to convert generator code to es5 code. Folks
using browserify will be able to use it very easily.

~~~
bnjmn
Great idea. Issue filed:
[https://github.com/facebook/regenerator/issues/20](https://github.com/facebook/regenerator/issues/20)

------
jessep
Thank you! This is so exciting. I've been wanting to try things like go style
concurrency ([http://swannodette.github.io/2013/08/24/es6-generators-
and-c...](http://swannodette.github.io/2013/08/24/es6-generators-and-csp/)) in
the browser, and this seems like it will help us get there. Granted, haven't
tried it yet, and really understand nothing about any of this, but ... Anyway,
hooray :)

~~~
jessep
Okay, tried it, and actually worked with the demo from that article! Yay.

------
zamalek
This is similar to my asyncscript pet project[1] (that was met with much
resistance on the Node.js mailing list as it was Yet Another CPS Framework).
It drew inspiration from the way that C# creates the state machines for
"yield" and "await". The project is dead (it only dealt with async calls and I
never got round to "enumeration generators"), but if you are wondering how
regenerator works I have a nice explanation at the bottom of readme.md.

[1]:
[https://github.com/jcdickinson/asyncscript](https://github.com/jcdickinson/asyncscript)

------
pornel
I couldn't find information why generator functions in JS require '*' in the
syntax (ES6 spec/wiki just states this as a fact, but no rationale). Does
anybody know?

Python manages to work fine without ugly wart in the syntax, and it seems to
me that presence of `yield` keyword in body is enough at syntactical level to
tell compiler that the function is a generator.

~~~
bnjmn
It means you can have generator functions that contain no yield statements,
which is not as crazy as it sounds. I've had to do `if False: yield` before in
Python to trick the language into treating a function as a generator. An
unyielding generator behaves so differently from a similar-looking non-
generator function that the extra syntax seems more than appropriate to me.

The asterisk also makes it trivial (using regular expressions) to tell whether
a string of code contains any generator functions.

"Explicit is better than implicit" is a rule of thumb that Python supposedly
values, but neglects to follow here!

