4 ms·
Since this article is specifically about Javascript: I think the implementation of async/await in the language is heavily constrained by a desire for backwards
by jffry 5y ago
Since this article is specifically about Javascript: I think the implementation of async/await in the language is heavily constrained by a desire for backwards compatibility.
After all, async/await is ultimately promises all the way down, so you can happily write code and let a compiler turn it into ES5 that runs anywhere.
If instead JS allowed you to shunt arbitrary function calls off into their own threads, then you would need bigger changes to the engines to support that, and you couldn't back-port that to vanilla javascript.
- divan 5y agoTo be honest, I find promises even worse concept for concurrent programming. At least I never think about things and behaviour in terms of "objects that will yield value in the future". To use promises I need to build a layer of conversion between "how my brain thinks about world" and "passing around promises" – and that's just textbook accidental complexity and unneeded cognitive load. The least cognitively expensive model for concurrent programming is CSP, precisely because it fits into how we humans reason about world.
- jseban 5y agoMe too, there is no concurrent programming in Javascript. It's a continuation passing style language and a single threaded runtime, I wish people would just spend a little time learning how that works and normal javascript will make a lot of sense and not look "yucky" anymore. And you will realise how great of a fit that is for UI programming and reacting to events from the user, where you don't have to think about blocking the UI thread like you need to in Java.