Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

276
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda