4 ms·
For those wanting to use async/await everywhere, right now, it can be transpiled using Babel or similar (in Babel you need to enable the "es7.asyncFunctions" fe
by tlrobinson 11y ago
For those wanting to use async/await everywhere, right now, it can be transpiled using Babel or similar (in Babel you need to enable the "es7.asyncFunctions" feature: https://babeljs.io/docs/advanced/transformers/#es7-experimental- https://babeljs.io/docs/advanced/transformers/#es7-experimen... )
- AgentME 11y agoCurrent versions of Babel default to having es7.asyncFunctions enabled.
- ilaksh 11y agoSerms like I still need --optional runtime and babel-runtime though, right?
- AgentME 11y agoYou need to do that, or include the global polyfill: https://babeljs.io/docs/usage/polyfill/ https://babeljs.io/docs/usage/polyfill/. If you're writing a library, use the runtime option. If you're writing a website or other standalone app, you should use the polyfill (especially if you use other libraries like React which depend on ES6 globals too).
- mistercow 11y agoAlso, if you're targeting a JS implementation with generators, but no await, Q has an async method that uses generators to achieve the same result, albeit with "yield" instead of "await" (in fact, I believe babel's experimental await support uses generators as an intermediate transform; sure looks like it from the code it generates). This means you can get await-like promise handling in Node.js using the --harmony_generators flag.