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

244
Views
Promesa de Javascript, todos los .then se ejecutan al mismo tiempo

En este momento, todos los console.log que siguen a .then se ejecutan al mismo tiempo. Quiero cada .luego esperar al anterior, ¿cómo puedo hacerlo?

 function doIt(sentence) { return new Promise((resolve, reject) => { setTimeout(() => { resolve(console.log(sentence)) }, 2000) }) } doIt('Place order') .then(() => setTimeout(() => { console.log('Cut the fruit') }, 2000)) .then(() => setTimeout(() => { console.log('Add water and ice') }, 2000)) .then(() => setTimeout(() => { console.log('Start the machine') }, 2000)) .then(() => setTimeout(() => { console.log('Select topping') }, 2000)) .then(() => setTimeout(() => { console.log('Serve the ice cream') }, 2000))
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Tienes que crear una cadena de promesas.

 function doIt(sentence) { return new Promise((resolve, reject) => { setTimeout(() => resolve(console.log(sentence)), 2000); }); } doIt("Place order") .then(() => doIt("Cut the fruit")) .then(() => doIt("Add water and ice")) .then(() => doIt("Start the machine")) .then(() => doIt("Select topping")) .then(() => doIt("Serve the ice cream"));

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!