I know that the callback function of setTimeout
, setInterval
, setImmediate
api is queued in macro task queue.
But, I'm not sure about addEventListener
.
Is the callback function of addEventListener is queued in macro task queue?
Check please :D
I know that the callback function of setTimeout, setInterval, setImmediate api is queued in macro task queue.
It's not. What is queued in the timer task-queue is a task. This task's steps will be responsible of executing the callbacks (through the fire an event algo). The callback itself is stored in memory.
For event listeners it's about the same, event callbacks are never queued in a task source, only tasks or microtasks are, and as part of these tasks's steps the events are dispatched and the callbacks are executed.
For instance you can very well have an event fire from a microtask (e.g the slotchange event, but you can also force it yourself with EventTarget#dispatchEvent()
), most native events are generally part of task (just search for the phrase to fire an event
in the HTML specs for examples), and you have loads of events that don't fire from any tasks nor microtask, but directly as part of the event loop processing, in the update the rendering step.