6 ms·
await/promises/etc mostly exist to solve the problem that JavaScript doesn't have threads so it can't wait for callbacks. About JavaScript, many other language
by throwasehasdwi 9y ago
await/promises/etc mostly exist to solve the problem that JavaScript doesn't have threads so it can't wait for callbacks.
About JavaScript, many other languages have had async/await for a long time. I have no idea why JS made such a huge deal of promises, I guess they're better than the callback hell before. Of course, in most languages using async isn't nearly as important for performance because they have thread pools.
Some interfaces aren't and won't be asynchronous (like Linux file IO) so eventually JS will support proper threads and we can stop talking about how great asynchronous programming is (it isn't).
- jrs95 9y agoNode has threads in C++ for that sort of thing. Async programming is a big deal for performance. That's essentially the main reason Node is any faster than Python. If you use fully async Python on uvloop, you can get comparable performance.
- balfirevic 9y agoIt is ultimately a failure of language and runtime that programmer has to manually specify where he wants to make asynchronous vs. synchronous functions to get the optimal performance. This blog posts elaborates on that better then I could do here, so I'm just going to link to it: http://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-function/ http://journal.stuffwithstuff.com/2015/02/01/what-color-is-y...
- jcelerier 9y ago> that programmer has to manually specify where he wants to make asynchronous vs. synchronous functions to get the optimal performance. programs aren't just pure computations. There are plenty of times when you want a specific event to happen at a specific time (as in, wall-clock), and plenty of times when you don't care when something computes as long as you end up getting a result at some point.
- throwasehasdwi 9y agoYou don't get reliable wall clock time unless you're working in RTOS. In a threaded OS everything in userland is async to an extent. In this school of thought, having to specify that something should be async manually could be seen as a failure of the language.
- jcelerier 9y agoon recent good hardware there is no problem being around 1ms accuracy.
- balfirevic 9y agoYes, but that should be call-time distinction, not a function declaration distinction. This is briefly mentioned at the end of the linked article. Edit: as other poster mentioned, async/await and promises also don't help with precise wall-clock time but that is entirely different matter.
- coldtea 9y ago>That's essentially the main reason Node is any faster than Python. v8's JIT is many times faster than Python in CPU bound tasks without any asynchronicity involved.
- flamedoge 9y agoPython also has async/await
- jdmichal 9y agoMaybe promises come before async/await, in an evolutionary sense. Same way that for-each loops seem to precede generators / yield. C# added Task before the syntax sugar of async/await. Java currently has Future, and I expect async/await to finally show up in about 10 years time...
- iainmerrick 9y agoawait/promises/etc mostly exist to solve the problem that JavaScript doesn't have threads async/await was popularized in C#, which does have threads.