Chapter XVI · Asynchronous JavaScript
Macrotask Queue
The macrotask queue (or task queue) holds standard asynchronous tasks like `setTimeout`, `setInterval`, and I/O events.
01 How It Works
Think of regular scheduled train departures leaving the station one by one per interval cycle.
The event loop processes one macrotask from this queue per cycle, after all microtasks have been completely cleared.
example.js
setInterval(() => console.log("Macrotask tick"), 1000);
1. Timers or I/O events finish and enqueue tasks.
2. Microtask queue is checked and cleared.
3. Event loop executes exactly ONE macrotask.
02 Practical Example
Here is how you might see this concept applied in real-world code:
practical.js
setTimeout(() => console.log("Macrotask execution"), 0);
Key Takeaway
Macrotasks represent standard asynchronous event tasks processed one per event loop cycle.