Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

415
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda