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

185
Views
How to add messages to the callback queue?

JS is a single threaded that can run only sync code. But there methods that are async by default, like setTimeout and running actions against the DB, or HTTP requests.

Those methods are added messages to the callback queue and by the time that the call stack is empty, the methods in those messages are applied to the call stack as well to be implemented.

But, how can I add a message to the callback queue by myself?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

In the browser environment, there are a couple of ways:

  1. setTimeout with a 0 interval (or similar), which queues a task
  2. queueMicrotask (relatively new, but easily polyfilled if the environment supports promises), which (you may have guessed!) queues a microtask

Node.js also has those, and a couple more that are more specific to its execution loop, like setImmediate (not expected to be standardized on browsers).

about 4 years ago · Juan Pablo Isaza Report

0

This article explains it very well:

https://dev.to/bipinrajbhar/how-javascript-works-web-apis-callback-queue-and-event-loop-2p3e

The setTimeout, setImmediate, http request, dom events ...etc are all part of the Web API that is implemented in the browser and also extended in Node.JS (setImmediate for example). They are here to add async to JS functionality. Therefore, manually adding new messages to the callback queue is possible only via the Web API.

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!