flow icon indicating copy to clipboard operation
flow copied to clipboard

Experimental support for ES7 async/await

Open aaronshaf opened this issue 12 years ago • 19 comments

I have fallen in love with 6to5 and traceur's support for async/await. I would love to be able to use this with flow.

aaronshaf avatar Nov 18 '14 19:11 aaronshaf

I'd love this too. I remember @benjamn built a recast transform for async await. Everyone I know who uses jstransform (ourself included) would love to switch to recast ASAP, so when we do it's nice to know there's a transform waiting.

Typing async/await wasn't too hard to do for Hack, so it shouldn't be too hard to do in Flow too, once there is demand for it!

gabelevi avatar Nov 18 '14 20:11 gabelevi

async/await is supported in regenerator proper right now; I think that es7-async-await package is old.

sophiebits avatar Nov 18 '14 20:11 sophiebits

That's right, I've stopped working on https://github.com/benjamn/es7-async-await in favor of handling async functions in Regenerator, because only Regenerator can take advantage of the optimization of creating a generator object directly, skipping the creation of the GeneratorFunction.

benjamn avatar Nov 18 '14 21:11 benjamn

I should also mention that 6to5 uses Regenerator for its async/await support!

benjamn avatar Nov 18 '14 21:11 benjamn

+1

amasad avatar Jan 16 '15 19:01 amasad

It would be particularly awesome if Flow could somehow warn when exceptions might be swallowed by Promises!

benjamn avatar Jan 16 '15 19:01 benjamn

Yes async await would be a very nice addition! Any updates on progress? :) :+1:

yornaath avatar Apr 12 '15 19:04 yornaath

it shouldn't be too hard to do in Flow too, once there is demand for it!

+1 demand :)

junosuarez avatar Apr 13 '15 16:04 junosuarez

+1 love this too.

jqwn avatar May 07 '15 03:05 jqwn

+1

I get Unexpected token function on my async keywords.

Is there anyway to workaround this?

vjpr avatar May 18 '15 19:05 vjpr

:+1:

jtremback avatar May 25 '15 00:05 jtremback

Async/await support added in v0.12.

bhosmer avatar Jun 16 '15 23:06 bhosmer

I'm still getting errors for the await* syntax.

johngeorgewright avatar Aug 10 '15 20:08 johngeorgewright

@johngeorgewright can you give an example?

samwgoldman avatar Aug 10 '15 21:08 samwgoldman

/* @flow */

function somethingParallel() {}
function somethingElseParallel() {}

async function somethingAsynchronous() {
  await* [
    somethingParallel(),
    somethingElseParallel()
  ];
}
 $  flow

.../test.js:7:8,8: Unexpected token *

Found 1 error

johngeorgewright avatar Aug 10 '15 21:08 johngeorgewright

$  flow --version
Flow, a static type checker for JavaScript, version 0.14.0

johngeorgewright avatar Aug 10 '15 21:08 johngeorgewright

@johngeorgewright Thanks. The closest thing I could find as far as documentation is this section of the proposal, but I'm not sure if that is being tracked along side async/await in the ES process.

I will note that Babel seems to understand this syntax, so it could very well be an omission here. @sebmck, sorry to drag you into this, but do you know what's up with this feature? Is it a part of the "standard" async/await feature, or is it on a separate schedule/phase?

samwgoldman avatar Aug 10 '15 21:08 samwgoldman

No worries at all. await* is from an early proposal. You can see a reference here. It's most likely going to be removed in Babel 6.0 as it's not on standards track.

sebmck avatar Aug 10 '15 21:08 sebmck

Ah, OK, sorry. So I'm to use await Promise.all()... I hadn't realised that. Thanks.

johngeorgewright avatar Aug 11 '15 10:08 johngeorgewright