▲ | tbrownaw 3 days ago | |||||||||||||
The `await` keyword means "turn the rest of this function into a callback for the when the Task I'm waiting on finishes, and return the resulting Task". Returning a Task only works if your function is declared to return a Task. The `async` keyword flags functions that are allowed to be transformed like that. I assume it could have been made implicit. You can do a blocking wait on a Task or collection of Tasks. But you don't want to do that from a place that might be called from the event loop's thread pool (such as anything called from a Task's completion callback), since it can lock up. | ||||||||||||||
▲ | captaincrowbar 2 days ago | parent | next [-] | |||||||||||||
"The `await` keyword means "turn the rest of this function into a callback for the when the Task I'm waiting on finishes, and return the resulting Task"." Oh my god thank you. I've been trying to wrap my head around the whole async/await paradigm for years, basically writing code based on a few black magic rules that I only half understand, and you finally made it all clear in once sentence. Why all those other attempts to explain async/await don't just say this I can't imagine. | ||||||||||||||
| ||||||||||||||
▲ | ivanjermakov 2 days ago | parent | prev [-] | |||||||||||||
> I assume it could have been made implicit Not quite. It gets ambiguous whether to wrap return or not. Example:
but async version is:
Although you can bake into the language one way or another. |