RafaelJan
RafaelJan

Reputation: 3606

Nodejs message queue vs macrotask queue

What is the difference between message queue and macrotask queue? Is it the same thing?

On Nodejs documentation here it says:

When setTimeout() is called, the Browser or Node.js starts the timer. Once the timer expires, in this case immediately as we put 0 as the timeout, the callback function is put in the Message Queue.

While, in this section, it says:

A setTimeout, setImmediate callback is added to macrotask queue

So, does message queue and macrotask queue is the same thing?

Upvotes: 3

Views: 291

Answers (2)

Bergi
Bergi

Reputation: 665286

It refers to the same thing here. One could say that "message queue" is a more general term, as in "the microtask queue and the macrotask queue are both message queues".

Upvotes: 1

Cookie Monster
Cookie Monster

Reputation: 51

If I am reading this right, it seems the "Message Queue" is a general term that is implemented using a few different queues.

In this section they explain:

A process.nextTick callback is added to process.nextTick queue. A Promise.then() callback is added to promises microtask queue. A setTimeout, setImmediate callback is added to macrotask queue.

Looks like the macrotask, microtask, etc. are specific parts of the implementation and have different attributes.

For example, execution order:

Event loop executes tasks in process.nextTick queue first, and then executes promises microtask queue, and then executes macrotask queue.

Found another easy explanation here.

Upvotes: 0

Related Questions