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

541
Views
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 answers
Answer question

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 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!