back

by danabramov·13y ago·view on hn ↗
Same problem like with the sibling post: this will ask two players simultaneously. My example waits for each player to provide a valid name in turn.
2 comments
If you're doing everything sequentially anyway, why bother with the awaiting part? As far as I can see your example would be functionally unchanged if you wrote the same code except without the await keyword.
Because it doesn't block the thread. The idea is that this code is executed inside of a thread that, if it blocks, will cause the application to hang. For example, in a GUI or a server. So, if its a thread driving a GUI, and it's blocked on user input, then the entire application interface will be unresponsive until it receives that input.
This. Specifically, I'm thinking about iOS prompts and alerts, they are not blocking.
Great comment! I missed that.
Well, if the Ask function should only run once at a time, it should block itself.
Imagine it's an iOS modal prompt. It doesn't block the thread, it sends an event.