Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#8266 closed bug (worksforme)

Queue type must be "fx" or it breaks

Reported by: Motty Owned by:
Priority: low Milestone: 1.next
Component: queue Version: 1.5
Keywords: Cc:
Blocked by: Blocking:

Description (last modified by jitter)

I found ticket #4127 with this same problem back in version 1.3 and it seems to have been reintroduced in version 1.5.

Here is a demo: http://jsfiddle.net/Mottie/GfWFM/

In the demo, switch the jQuery version from 1.4.4 to 1.5 to see the problem, then change the queName variable from 'fx2' to 'fx'.

Change History (2)

comment:1 Changed 12 years ago by jitter

Component: unfiledqueue
Description: modified (diff)
Priority: undecidedlow
Resolution: worksforme
Status: newclosed

Thanks for taking the time to contribute to the jQuery project by writing a bug report and providing a test case!

After checking your report and test case I came to the conclusion that this isn't a bug. The behavior you see is caused by a bug fix in 1.5 (for a memory leak that was present in 1.4.4). Check this commit for the code change.

Your code only worked in 1.4.4 because the empty queue object wasn't removed from the cache in 1.4.4 (thus leaking memory). In 1.5 with the bug fix your code hits a "race condition", if you have some understanding of the inner workings of queue/dequeue you can verify that yourself by looking at this piece of code.

When you dequeue the last function on the queue the queue is empty, this last function calls startLoop which re-fills the queue and calls next which logs "7" and dequeues the first function on the stack which executes a setTimeout. Now the code "returns" and unwinds the call-stack and ends up in .dequeue again where it started the execution of the "last" function on the queue. It still knows that the queue was empty and thus removes it. When the setTimeout function runs the queue is no longer there (=empty) your code logs 0 and ends.

So all you need to do is wrap the startLoop call in a setTimeout do as shown in this example

I hope the explanation was sufficiently clear.

Last edited 12 years ago by jitter (previous) (diff)

comment:2 Changed 12 years ago by Motty

Thank you sir!

Note: See TracTickets for help on using tickets.