Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

417
Views
Is this await Task.FromResult necessary?

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)

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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));
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!