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

275
Views
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 answers
Answer question

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 Report

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 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!