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

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

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

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