I have a ASP.NET WEB API controller with a method like this:
[HttpGet]
[Route("some/route/to/endpoint")]
public Task<Data> DoStuffAsync()
{
var somevar = Guid.NewGuid();
return DoSomeInternalStuffAsync();
}
private async Task<Data> DoSomeInternalStuffAsync()
{
var result = await SomeReallyInternalThingsAsync();
return result.Data;
}
What is the difference on eliding the async/await and to actually use it like:
[HttpGet]
[Route("some/route/to/endpoint")]
public async Task<Data> DoStuffAsync()
{
var somevar = Guid.NewGuid();
return await DoSomeInternalStuffAsync();
}
I read a lot of articles and Stackoverflow posts, but it is still unclear to me:
- What is the internal handling of a controller method returning a Task VS returning an awaited task?
- Will the controller method be awaited in each case or is returning a Task on a controller method a pure synchronous operation?
Articles read so far: Eliding async await, Asynchronous Programming, Stackoverflow Thread 1, Stackoverflow Thread 2
Update: My questions are answered in the comments.