I’ve been taught about it in the following fashion, I found it to be quite a clear and concise explanation:
//this is pseudocode
async Method()
{
code;
code;
await something;
moreCode;
}
When Method
is invoked, it executes its contents (code;
lines) up to await something;
. At that point, something;
is fired and the method ends like a return;
was there.
something;
does what it needs to and then returns.
When something;
returns, execution gets back to Method
and proceeds from the await
onward, executing moreCode;
In a even more schematic fashion, here’s what happens:
- Method is invoked
code;
is executedsomething;
is executed, flow goes back to the point whereMethod
was invoked- execution goes on with what comes after the
Method
invocation - when
something;
returns, flow returns insideMethod
moreCode;
is executed andMethod
itself ends (yes, there could be something elseawait
-ing on it too, and so on and so forth)