Question

I am a little confused about some terms in the answer of this question: What is the event precedence in JavaScript?

Is there a difference between event loop and task queue and how big are can these queues?

Because when I have set an Interval with setInterval() and interrupt this with an alert() then the intervals are dropped for the time where the alert is showing up.

Was it helpful?

Solution

Heap : Stores All variables , Objects , Functions and To all this memory is allocated

Event Queue : He is the person contains list functions TOBE EXCECUTED By Stack.

Stack : He is the main person who EXECUTES FUNCTIONS held by Event queue

Event Loop :

  1. He is the person(manager) who is in contact with Event Queue And Stack.

  2. What he does Is .Ifff The stack is empty and Event Queue Contains Functions to execute.then push the first function from Event Queue to stack

visual Example 1 : latentflip

OTHER TIPS

This is an implementation detail - the specification is saying that an event loop can be use multiple task queues to store events. Presumably there is no practical limit to the size of the queues.

For example, mouse/keyboard events could go into a special INPUT task queue that has a higher priority than other tasks, perhaps to make the UI more reponsive.

alert will interrupt the processing of events because it is a synchronous operation. Presumably any applicable events would be queued in the meantime.

I think you're just seeing a protection mechanism in setInterval(). If setInterval() isn't able to keep up with the desired interval rate, then it will skip intervals because if it didn't, then extra intervals might build up forever and that's not good as it would saturate a queue somewhere.

From everything I've seen in the queueing behavior, intervals and events go in the same queue and are processed in the order they were meant to occur. The difference is that if there is already a setInterval() callback in the queue that has not yet been processed, it won't put another one in the queue (thus skipping it).

Mousemove events are also processed specially so you can't fill the queue up with them either.

The question you have posted is really a popular one, but you were not able to put it with clarity.

first things first js is synchronous by nature. The browser helps make it kind of asynchronous.

The call stack of js works synchronously but whenever it encounters asynchronous piece of code (setTimeout(),HTTP requests) it is sent to the browser's web api's.

where it is taken care of, like waiting for the response of the request or waiting for the timeout to complete. (The async piece of code is removed from the call stack for the time being, and call stack moves onto the next task)

After the web api recieves the response or the timeout fn ends it is then sent to the task queue which queues all the async code

It is where the event loop actually comes into play. It first check's whether the call stack is empty if it is then the first element of task queue is pushed onto the stack.

So in your case when you alerted ,it blocked the call stack and hence setInterval couldnt be pushed onto the call stack

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top