MatAtBread / fast-async

605 stars 21 forks source link

can't call await on normal functions + can't use es2015 preset #32

Closed sedubois closed 7 years ago

sedubois commented 7 years ago

The idea to use fast-async in Next.js came up, but there were these concerns:

Is that accurate? If these limitations do exist, is there a possibility/plan to address them? How do other users circumvent them?

matAtWork commented 7 years ago

This is discussed in https://github.com/MatAtBread/nodent/issues/68 - the solution is to specify the compiler option wrapAwait.

Not being a Babel expert, I can't say for sure that the es2015 preset is problematic. A quick read through the issues here and in https://github.com/MatAtBread/nodent/issues/ indicates a number of people have successfully used them together. I have a suspicion the trick is to apply 'fast-async' before the other presets.

Let me know how you get on as I know other people would like a definitive guide.

sedubois commented 7 years ago

Thanks I passed on the info over here: https://github.com/zeit/next.js/issues/851#issuecomment-276014739

matAtWork commented 7 years ago

You're welcome. Oh, and as of fast-async 6.2.0 (if I remember correctly), the option "spec": true sets the flags to be the most compatible with the spec. Combine with the "es6target": true if you're running on a platform that handles arrow functions.

{
  "plugins": [
    ["fast-async", {
      "spec":true
    }]
  ]
}
Rush commented 7 years ago

@matAtWork idea: you could release your own es2015-fast-async preset with all the best default options and everything working OOTB :)

matAtWork commented 7 years ago

Not being a babel expert, I don't really feel qualified to maintain it properly, but I think others have had the same idea, see https://www.npmjs.com/package/babel-plugin-fast-async and the various presets in https://www.npmjs.com/browse/depended/fast-async

matAtWork commented 7 years ago

If anyone does come up with a definitive preset or guide on using fast-async with the various Babel presets, please feel free to generate a PR for the README!

MatAtBread commented 7 years ago

@sedubois - In the absence of anything to fix here, I'll close this issue. Feel free to re-open if you need any more help.