• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

177
Vistas
Microtask Queue waits for all operations to be performed before moving to the callstack?

As far as I understood, I expected them to be printed according to the resolution time of each one (after the callstack is empty), to finally print the setTimeout() message.

However, all solutions are printed when the most time-consuming task is completed. Specifically, it is only when the promise operation of the second call to recursionSecond() is completed that all the others are also printed.

    setTimeout(() => console.log('timeout in 0'), 0);
    
    function recursionFirst(number) {
        return new Promise((resolve, reject) => {
            for(let i = 0; i > (number * (-1)); i--) {
                if(i === (number * (-1)) + 1) resolve(i)
            }
        })
    }
    
    function recursionSecond(number) {
        return new Promise((resolve, reject) => {
            for(let i = 0; i < number; i++) {
                if(i === number - 1) resolve(i)
            }
        })
    }
    
    recursionFirst(40) 
        .then(x => console.log(x))
    
    recursionFirst(400) 
        .then(x => console.log(x))
    
    recursionFirst(400) 
        .then(x => console.log(x))
    
    recursionSecond(10) 
        .then(x => console.log(x))
    
    recursionSecond(2000000000) 
        .then(x => console.log(x))
    
    recursionSecond(1000) 
        .then(x => console.log(x))
    
    console.log("Hi!")

about 3 years ago · Juan Pablo Isaza
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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda