3 ms·
> This has been such a mistake, now it needs "await" all over the code. Await is just a syntactic sugar, and quite a good one I think. You need to seperate asy
by gitgud 5y ago
> This has been such a mistake, now it needs "await" all over the code.
Await is just a syntactic sugar, and quite a good one I think. You need to seperate async and sync functions somehow in order to prevent code from blocking the main thread.
> Programs run synchronously and only needs to go async every once in a while but things get pretty verbose from it.
Well I would argue that most things a program does (besides crunching raw data within memory) is asynchronous. Network requests, painting to screen, polling IO ports, fetching from the Filesystem, handling user interaction... these are all examples of asynchronous operations.
It's simpler to have a single-threaded event-loop rather than spinning up threads and keep track of them, preventing deadlocking etc...
A single-threaded event-loop also has the benefit of being incapable of dead-locking, as only one thread is accessing variables at any given point.