4 ms·
I'm not a beliver, so I may be missing something important... As far as I can see, await makes it possible to do things like: - UI Thread starts Thread X to d
by marcosdumay 13y ago
I'm not a beliver, so I may be missing something important...
As far as I can see, await makes it possible to do things like:
- UI Thread starts Thread X to do something slow;
- Thread X is processing, in the meantime the user clicks on something that requires X's result;
- Only now the UI thread stops, waiting for X.
Your program stay responsive, unless it's completely not able to do so.
As I said, I still don't think it's a so important feature. It is quite rare that one needs such kind of coordination in UI programs, and there are better mechanisms for no-interactive software (that optimize for throughput, not responsiveness)... As a second thought, it may be very relevant for games, I don't know.
I also don't get why the node.js people consider it so important to have concurrence at a web server. For me, it only makes sense for sites that have less concurrent requests than server cores, AKA: nobody.
- danabramov 13y agoNo, you got it wrong. Await never blocks the UI thread. Instead, the compiler rewrites your sequential code into a state machine. When you await on a task, the compiler turns this into scheduling a continuation. No blocking.
- marcosdumay 13y agoYep, I got it wrong. Thanks for pointing that. Now I'm also wondering how I'd use something like that in an imperative language... Well, I have some studying to do.