Its 2023 why aren't people using async await.

Because they are not the panacea, and presents inherent problems and big misuse problems.

A few people hate it with reason, but many more hate it because they don't understand them and that leads to a lot of unexpected bugs.

Some inherent problems:

  • Coloured functions, despite there not being any problem in mixing async and normal functions, there is an artificial limitation due to semantic rules put in place in a lot of languages that implement it (js, python ...) This lead to a lot of duplicated code.

  • Complex unneeded abstractions on the internals, and mixings of concepts. In a lot of async implementations promises, coroutines, generators, continuations and other terms are mangled together. Lots of this concepts are similar, and some can be emulated with another trivially, or are interchangeable; but there is no inherent dependency between promises and async functions for example, however they are in some implementations.

  • Contrary to common belief, async functions and green threads are not quicker nor cheaper. Context switch in user-land, specially on an interpreted run-time are more costly in time and memory than native threads.

  • Sometimes different low and high level scheduler are used at same time/level. For example the js run-time scheduler, with the browser scheduler, or on node-js with native threads.

  • Not a problem per se, but confuse the general terminology. Async functions are not really asynchronous, and normal (sync) functions are not synchronous at any level. They are just self-suspendable functions (They are just asymmetric coroutines). They just permit to model concurrency, if they are synchronous or not depends on the underlying systems.

Some misuse problems:

  • Some people think that async functions make code inherently quicker, or that this kind of code runs on parallel. In practice, is easy to make async code slow, and make async code where normal code must be used.

  • There is the idea that with collaborative multithreading (async functions) all concurrency problems, race conditions and deadlocks, disappears, because you have the control. Sometimes this things are inherent not even to the algorithm, but to the problem. However this idea makes some devs slippy and even use susceptible global vars. As continuation with the previous issue, some think that it make code inherently lock-less, and if that you use locks you are doing async badly.

This misconceptions causes that a lot of concurrency problems arise, making async hard. Although in reality it's not more difficult than the old concurrency.

All this makes people to be reluctant to use async.

For the comparison between .then() and async, no one is more legible than the other. There is just some cases when one is more legible than the other. There is a point that you can wrap in your head the full flow of your program. In the end is a preference. That said I don't know if in js is a difference of behaviour in the effective event loop when using .then() vs async, but is probable and a potential motive that can make people choose one over another.

/r/webdev Thread