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

402
Views
¿Cuál es el impacto de await y .then() en la pila?

Tengo problemas para entender el flujo de control en el siguiente código. La línea await en await setTimeout(() => console.log("Await timeout executed"), 0) parece devolver el control al subproceso principal, lo que hace que 'I am in main()' se registre en la consola . Si elimino await , el orden de la salida cambia: "La función terminó de ejecutarse" ahora viene antes de "Estoy en el hilo principal". Entiendo el resto del código, pero no entiendo cómo se ve la pila aquí. ¿ await y .then() siempre devuelven el control a la persona que llama? Si es así, ¿cómo sabe el programa que debe volver a poner esas funciones en la pila? Gracias.

 async function test () { console.log("Execution starting"); setTimeout(() => console.log("Timeout executed"), 0); await setTimeout(() => console.log("Await timeout executed"), 0); Promise.resolve(5).then(function log() { console.log("Hello from the first promise!") }) console.log('The function is done executing') } test() console.log('I am in main()') //Execution starting //I am in main() //The function is done executing //Hello from the first promise! //Timeout executed //Await timeout executed
about 4 years ago · Juan Pablo Isaza
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!