Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

277
Vistas
How to explicitly push a function inside callback queue?

I want to run a function namely 'callbackfn' after the setTimeout function is being executed .If i run it in my global execution context then only when the code inside callbackfn is being executed then setTimeout Function will run as it will go inside callback queue and will be on hold until the lines in the global execution context.

But what i want is to execute callbackfn after the setTimeout is being executed.For that i have to push the callbackfn inside callback queue.So,how can we explicitly push it inside callback queue.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can pass the callbackfn as third parameter to the setTimeout. The callback function will execute once the setTimeout function runs.

function callbackfn() {
    console.log('func is executed');
}

setTimeout(function(callback) {
    callbackfn();
}, 3000, callbackfn);
about 4 years ago · Juan Pablo Isaza Denunciar

0

The short answer is you can't push your function directly to the queue without something like setTimeout. to understand why you should know

  1. setTimeout is a web API feature that takes the ref of you're function and after the timer is done it pushes the function to the callback queue
  2. the event loop won't dequeue any function from the callback queue to the call stack until all the synchronous code is executed then it checks the microtask queue first
  3. finally if you don't have any waiting functions in the call stack and in the microtask queue (queued functions from promises and mutation observers) it starts to check the callback queue
  • you can check this blog for more information
  • if you're a video person check this
about 4 years ago · Juan Pablo Isaza Denunciar
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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda