Re:How JavaScript works: Event loop and the rise of Async pr...
by genzoman on Saturday October 14, 2017 @09:34AM
(#15472097)
The async/await paradigm of C#/Typescript fixes this very nicely IMO.
[ Parent
| on HN ]
Re:How JavaScript works: Event loop and the rise of Async pr...
by Jizzle on Saturday October 14, 2017 @11:05AM
(#15472463)
I quite like async/await except that it's annoyingly easy to produce a deadlock, and given a snippet, it's not obvious that such a deadlock should occur.
Re:How JavaScript works: Event loop and the rise of Async pr...
by zzbzq on Saturday October 14, 2017 @11:54PM
(#15475804)
Ironically it is essentially the event loop which causes the deadlock in C#.
Depending on what framework/runtime you're in .NET will schedule the await continuation on something called a "SynchronizationContext" which has ~3 different forms but it's basically an event loop/message loop which queues up each continuation on the original thread.
The problem occurs when you use .Wait() or .Result instead of 'await'. This causes the function to spin waiting for the Task to finish, which of course it never will if it has a continuation trying to dispatch into that same event loop.
This problem doesn't really happen at all under some circumstances, such as if the async chain starts on a background thread, or in .net core where they've removed the SynchronizationContext, hence no event loop, hence no problems.
Re:How JavaScript works: Event loop and the rise of Async pr...
by rco8786 on Saturday October 14, 2017 @12:02PM
(#15472730)
Do you have an example? I’ve never seen a deadlock in Js. I’m trying to think of how it’s even possible? Async/await is just super around promises anyway.
Re:How JavaScript works: Event loop and the rise of Async pr...
by Jizzle on Saturday October 14, 2017 @12:32PM
(#15472906)
Oops, should've specified C# specifically, in which deadlock has become notorious. I don't think there's anything wrong with async/await per se. It looks to me like the linearity of js engine event loops wouldn't produce the same problem.