3 ms·
Thanks to the async/await keywords, modern javascript is not a callback hell anymore.
by speedgoose 6y ago
Thanks to the async/await keywords, modern javascript is not a callback hell anymore.
- jacquesm 6y agoNo, now you get it all mixed up. One library will use callback functions you supply, another will use callbacks but inline them and yet another will use async/await. And you, the application developer are left somewhere in the middle. Oh, and you can't use 'await' in the main thread of your JS, you can only use it from within another async function, so when you need it most - for instance during application start-up - it isn't available.
- speedgoose 6y agoYou can use promisify for the first one. For the second one I think these libraries doing that but still not supporting promises are not that common anymore but nothing you can't do with promises yourself. Javascript has a single thread, but I see what you mean and it has been fixed recently. To support older versions you can simply declare an anonymous async function and execute it immediately.
- doubleunplussed 6y agoI think of it the other way around: Thanks to javascript being single-threaded, we now have async/await keywords strewn throughout the software ecosystem where they provide no benefit.
- war1025 6y agoAsync is basically a super convenient way to interact with an event loop. Any time you call `await` you are saying "schedule an event on the event loop, and call back into this method with the result once it's available" Multi-threaded code is good for some things, but often you need an event loop to keep things reasonable (GUI code for example). That's where async / await really shines.
- anonymoushn 6y agoThis is pretty unfortunate. I expect that if JS had gotten fibers and a switch primitive, other languages would have copied that, but now users of unrelated languages are stuck with low-quality things forever.
- mywittyname 6y agoYeah, but now we have this weird mix of awaits, thens, and missing awaits that you're not sure were intentional. I may be in the minority here, but I kind of prefer callback hell to async hell. It's fine on projects with one or two devs, but more than that and the situation seems to devolve into tabs-vs-spaces, where one group finds the other incomprehensible and won't use it.