Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

542
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda