Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the 'fx' queue in jquery auto start?

Tags:

jquery

I have read many answers and blog posts on the jQuery queues... and specifically this particular answer has helped a lot - https://stackoverflow.com/a/3314877/1315811 . But, both standard docs on jquery.com and the answer above got me to look at the jquery code http://code.jquery.com/jquery-1.7.2.js

What I cannot understand - from the code - how does the 'fx' (default) queue auto-start. Especially after the queue has been emptied.

For example on a custom queue, when you manually start the queue, and the queue runs out of functions to call, any reference to the queue are no longer invalid, so I would expect somewhere in the jquery code an attempt to figure out the state of the queue and if it was empty auto start it? The code kinda demonstrates what I ran into, if I am just missing a piece of code (I am look at line: 2060-2160 in the above mentioned code) please let me know.

> var aq = $({});
> aq.queue("mp").length
0
> n1 = aq.queue("mp")
[]
> n1.length
0
> aq.queue("mp", function (next) { setTimeout(next, 5000); })
[Object]
> aq.queue("mp", function (next) { setTimeout(next, 5000); })
[Object]
> aq.queue("mp", function (next) { setTimeout(next, 5000); })
[Object]
> n1.length
0
> aq.queue("mp").length
3
> n1 = aq.queue("mp"); // reset n1 to the "new" queue...
> n1.length
3

Also, if any part of this is unclear, please let me know and I will update accordingly.

like image 487
mspisars Avatar asked Nov 14 '22 05:11

mspisars


1 Answers

This bit of code within the queue code handles the auto-start:

if ( type === "fx" && queue[0] !== "inprogress" ) {
    jQuery.dequeue( this, type );
}

If the queue being queued is fx and the queue is not already in progress, dequeue is called.

like image 182
James Montagne Avatar answered Dec 18 '22 09:12

James Montagne