4 ms·
Is using async/await through babel a good idea? When I last looked at it I thought it was using a busy loop which didn't seem like such a great idea to use in s
by foota 11y ago
Is using async/await through babel a good idea? When I last looked at it I thought it was using a busy loop which didn't seem like such a great idea to use in shipping code.
- tlrobinson 11y agoIt's fine. It transforms async functions into a state machine.
- nostrademons 11y agoIt's okay but clumsy. It's a state machine, not a busy loop, but the compiled code is a lot more verbose than the input code (and so you pay a latency penalty on the client). The developer experience is also sub-par: you'll get regenerator stack frames in any of your stack traces, and it interacts poorly with babel-watch. You can do it, it's not insane, but native async/await will be much, much nicer.
- tlrobinson 11y agoCan you elaborate on "it interacts poorly with babel-watch."?
- nostrademons 10y agoIIRC under babel-watch it required me to include babel-polyfill at the top of my main script, but under babel-node it prevented me from including babel-polyfill at the top of my main script. (babel-polyfill has a check so that it can only be required once, and errors out otherwise.) That meant I needed to keep commenting/uncommenting that line when I wanted to debug things. There were also cases where I wasn't sure if babel-watch was reloading dependencies properly if I used async code in a file, which is why I had to keep switching to babel-node or running the code through babel and inspecting the generated code to debug. Overall, it just felt very new and unpolished (which I guess it was...I was working with it around March, so babel-watch was < 1 month old and babel async/await was about 2-3 months at the time) to be relying on all the time.
- deleted 11y ago[deleted]
- hzoo 11y agoIf you don't want to use regenerator and your environment supports generators already you can use the async-to-generator transform https://gist.github.com/rauchg/8199de60db48026a6670620a1c33b700 https://gist.github.com/rauchg/8199de60db48026a6670620a1c33b...
- AgentME 11y agoAsync/await is just syntax-sugar around Promises. No busy loops involved. (Those generally don't work in Javascript anyway.)
- BinaryIdiot 11y agoThis overlooks Promises needing to be polyfilled. Though that's certainly not using busy loops either (though most of what I've seen overlooks more performant setTimeout(fn, 0) alternatives which is unfortunate).
- AgentME 10y agoAsync/await already needs to be transpiled in for most browsers, so Promises needing to be polyfilled seems like the least of your problems.