Home Return Type of an Immediate await vs Postponed await
Reply: 0

Return Type of an Immediate await vs Postponed await

user730
1#
user730 Published in April 22, 2018, 12:56 am

I am seeking clarification as to why an immediate await returns the type of the asynchronous, non-void task whereas postponing the await returns the task itself. If my terminology in the title or elsewhere is incorrect, please let me know.

private async Task<string> GetUserId(Guid id)
{
   string thisUserId = null;
   ... do stuff ...
   return thisUserId;
}

public async Task<IActionResult> MyFunc(Guid id)
{
   var a = await GetUserId(id);
   var b = GetUserId(id);
   ... do stuff ...
   await b;

   return Ok(true);
}

Why is a of type string while b is of type Task<string>?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.314467 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO