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

550
Vistas
What is the difference between awaiting on promose (that has setTimeout) vs awaiting on setTimeout?

What is the difference between:

  1. await new Promise(resolve => setTimeout(resolve, 5000));

  2. await setTimeout(resolve, 5000);

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

await setTimeout(resolve, 5000); does nothing extra, it's the same as setTimeout(resolve, 5000);

await will pause code execution of the containing function until a promise is resolved. The setTimeout function does not return a promise, it is not an async function. Hence, await is redundant, it doesn't do anything special in this case.

Your first bit of code does return a promise. It takes the legacy non-promise-based setTimeout function and turns it into a promise form. It then awaits this promise form.

You should learn about promises to gain a better understanding of what's going on. The key thing to note here is the difference between callback-based functions (like setTimeout) and modern promise-based functions.

about 4 years ago · Juan Pablo Isaza 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