I've just a question that came to my mind since I've started working on an existing project: Consider the following snippet of code
public async Task<IHttpActionResult> DoSomething(Guid token)
{
var data= await repository.GetDataAsync(token);
return await Task.FromResult(Ok(data));
}
As far I've seen when using await I can just have return Ok(data)
But I've been told that not using that Task.FromResult would lead to async problems... where can I find more info on this point? It's used in Web API Full Framework (not.NET Core)
Absolutely no!
You should use Task.FromResult(Ok(data)) only if you receive data from the repository synchronously, else if you have at least one await keyword it's an unnecessary resources waste.
So, you can rewrite your method this way:
public async Task<IHttpActionResult> DoSomething(Guid token)
{
return Ok(await repository.GetDataAsync(token));
}