Test case for jQuery Ticket 8266
.queue race condition
by jitter
HTML
<div id="results"></div>
<!-- to see this bug, change the jQuery version from 1.4.4 to 1.5
it will work in 1.5 if you change the queName from 'fx2' to 'fx',
but it still acts strangely
-->
JavaScript
var queName = 'fx2',
iterations = 0,
obj = $(document),
results = $('#results'),
delay = 50,
next = function() {
results.append(' ' + obj.queue(queName).length);
obj.dequeue(queName);
},
loop = [
function() { setTimeout(next, delay); },
function() { setTimeout(next, delay); },
function() { setTimeout(next, delay); },
function() { setTimeout(next, delay); },
function() { setTimeout(next, delay); },
function() { setTimeout(next, delay); },
function() { setTimeout(startLoop, delay); }
],
startLoop = function() {
if (iterations++ < 5) {
results.append('<br>Iteration = ' + iterations + ', que length: ');
obj.queue(queName, loop);
next();
}
};
startLoop();