4 ms·
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.
by danabramov 13y ago
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.
- captaincrowbar 13y agoIf 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.
- scott_s 13y agoBecause 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.
- danabramov 13y agoThis. Specifically, I'm thinking about iOS prompts and alerts, they are not blocking.
- gruseom 13y agoGreat comment! I missed that.
- singlow 13y agoWell, if the Ask function should only run once at a time, it should block itself.
- danabramov 13y agoImagine it's an iOS modal prompt. It doesn't block the thread, it sends an event.