3 ms·
> async/await allows you to do multiple things in parallel. I don't see how you can do that in the virtual threading model, although I haven't used it and only
by e63f67dd-065b 4y ago
> async/await allows you to do multiple things in parallel. I don't see how you can do that in the virtual threading model, although I haven't used it and only read this article. You would have to spin up threads and wait for them to finish, which IMO is much more complicated and hard to read
I think there's a fundamental point of confusion here. In both python and JS, you can't do anything in parallel, since node/v8 and cpython are single-threaded (yes if you dip down into C you can spawn threads to your heart's content). You can only do them concurrently, since only when a virtual thread blocks can you move on and schedule another thread in your runtime.
In c++ (idk the java syntax, imagine these are runtime threads):
std::thread t1(doThingOne, arg1);
std::thread t2(doThingTwo, arg2);
t1.join();
t2.join();
// boost has a join_all
I'm sure there's some kind of `join_all` function in Java somewhere. Imo this is even more clear than your async await example: we have a main thread, it spawns two children, and then waits until they're done before proceeding.
The traditional problem with async/await is that it forces a "are your functions red or blue" decision up-front (see classic essay https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-function/ https://journal.stuffwithstuff.com/2015/02/01/what-color-is-...).
> Finally it's generally much easier implement new libraries with a promise/future based async/await system than with a system based on threads
How so? Having written a bunch of libraries myself, I have to say that not worrying about marking functions as async or not is a great boon to development. Just let the runtime handle it.
- mgraczyk 4y agoThe first part is semantics, yes I understand that python is running one OS thread at a time with a GIL (for now). Just pretend I used the word "concurrent" instead of parallel in all the places necessary to remove the semantic disagreement. Whether threads and joining vs async/await is clearer is a matter of taste and familiarity. I find async/await much more clear because that's what I am more used to. Others will disagree, that's fine. I suspect more people will prefer async/await as time goes on but that's my opinion. > not worrying about marking functions as async or not is a great boon to development. I don't really see why this is a big deal. You can change the function and callers can change their callsite. There are automated lint steps for this in python and javascript that I use all the time. It's not any different to me than adding an argument or changing a function name.
- gbear605 4y agoPart of the difference with Java is that a lot of libraries haven’t changed in twenty years because they already work. Adding async/await would probably mean writing an entirely new library and scrapping the old already working code, while green threads allow the old libraries to silently become better.
- anonymoushn 4y agoWhen you add an argument you don't have to change all callsites of transitive callers.