I've been dealing quite a lot with async await lately (read every possible article including Stephen's and Jon's last 2 chapters) , but I have come to conclusion and I don't know if it's 100% correct. - hence my question .
Since async
only allows the word await to be present , i'll leave async
aside.
AFAIU , await is all about continuation . instead of writing functional (continuational) code , write synchronous code. ( i like to refer it as callback'able code)
So when the compiler reaches await
- it splits the code to 2 sections and registers the second part to be executed after the first part is done ( I don't know why the word callback
isn't used - which is exactly what is done). ( meanwhile working - the thread is back doing other things).
But looking at this code :
public async Task ProcessAsync()
{
Task<string> workTask = SimulateWork();
string st= await workTask;
//do something with st
}
public Task <string> SimulateWork()
{
return ...
}
When thread reaches await workTask;
it split the method to 2 sections . so after SimulateWork
is finished - the continuation of the method : AKA : //do something with st
- is executed.
all ok
But what if the method was :
public async Task ProcessAsync()
{
Task<string> workTask = SimulateWork();
await workTask; //i don't care about the result , and I don't have any further commands
}
Here - I don't need continuation , meaning - I don't need the await
to split the method which means - I don't need async /await here at all ! and still I will have the same results/behaviour !
So I could do it like :
public void ProcessAsync()
{
SimulateWork();
}
Question:
- Was I 100% correct with my diagnostics ?