Is there a difference between event loops and task queues in browsers?

I am a little confused by some terms in the answer to this question: What is the priority of an event in JavaScript?

Is there a difference between an event loop and a task queue, and how large are these queues?

Because when I set the interval with setInterval () and interrupted it with alert (), the intervals will be discarded for the duration of the warning.

+4
source share
3 answers

Heap : stores all variables, objects, functions and all this memory is allocated

Event Queue : It contains the functions of the TOBE EXCECUTED list. Stack .

Stack . He is the main person who EXECUTE FUNCTIONS held by the Event Queue

Event loop :

  • He is a person (manager) who is in contact with the Event Queue and the Stack .

Ifff empty and Event Queue Contains > Functions . , then push the first function from the event queue onto the stack

Visual Example 1 : latentflip

+5
source

This is an implementation detail - the specification states that the loop event can use several task queues to store events. There seems to be no practical limit on the size of the queues.

For example, mouse / keyboard events can go to a special INPUT task queue, which has a higher priority than other tasks, possibly to make the user interface more receptive.

alert interrupts event processing because it is a synchronous operation. Presumably, any applicable events will be queued at the same time.

+2
source

I think you see the protection mechanism in setInterval() . If setInterval() not able to keep up with the required interval speed, then it will skip intervals, because if it is not, then additional intervals can accumulate forever, and this is not as good as if it saturate somewhere turn.

From everything that I saw in the queue process, intervals and events go in one queue and are processed in the order in which they were supposed to happen. The difference is that if there is no processed setInterval() request in the queue, it will not queue another one (thus, skipping it).

Mousemove events are also handled specifically so that you cannot fill them as well.

+1
source

All Articles