facebook / regenerator

Source transformer enabling ECMAScript 6 generator functions in JavaScript-of-today.
http://facebook.github.io/regenerator/
MIT License
3.83k stars 1.16k forks source link

Is it possible to regenerator just async and not generator? #219

Open tolmasky opened 9 years ago

tolmasky commented 9 years ago

I'm now operating under an environment that supports generators out of the box. I'd still like to convert my async functions however. Babel has asyncToGenerator for this, but that seems to behave pretty differently than regeneratorRuntime.async() (no AwaitArgument, etc). So...

  1. Is regneratorRuntime.async() indeed the ideal for this situation (I feel like it is)
  2. What is the difference between what regenerator supports and the asyncToGenerator support in Babel (no handling of await + yield?).
  3. Is it possible to get regenerator to just regenerate awaits and not yields?
benjamn commented 9 years ago

I've been meaning to update https://www.npmjs.com/package/es7-async-await to behave more like Regenerator (i.e. do everything but transpile generators). That transform will still create a GeneratorFunction for each async function call, though, when all you really need is a single generator object.

Standards-wise, it seems like await + yield is heading in the direction of AsyncIterator, which is something Regenerator supports but es7-async-await does not (yet).

If we didn't have to deal with both await and yield, then we wouldn't need the AwaitArgument wrapper. I think the future has a place for both, though, so I'm reluctant to forbid yield just yet.