4 ms·
Writing multi-threaded programs is much, much harder than single-threaded code. I think part of the attraction of async/await is that you can write mostly non-c
by olau 6y ago
Writing multi-threaded programs is much, much harder than single-threaded code. I think part of the attraction of async/await is that you can write mostly non-concurrent code. But then it gets extremely important that you're aware when you might have concurrency. For instance:
x = get_something_from_global_state()
y = foo()
insert_into_global_state(x, y)
If the program is suddenly possibly concurrent when calling foo(), then perhaps x is no longer valid. Good luck debugging that. await foo() makes it much more obvious.
Now, of course, in scenarios where you don't really care about this property, e.g. if you're dealing with a database in another process where it is obvious that stuff may happen behind your back, or if you don't actually have any concurrency, I get that await is probably pretty annoying.