As explained in another question, If the queue being queued is fx and the queue is not already in progress, dequeue is called.
.
That is great that the default queue is smart enough to auto start. But how can I replicate the same functionality, auto starting when the queue is empty, for my custom queue?
My problem is I am receiving Pusher calls (ajax calls that come to the page) that activate the code below to add a new name to #tickerlist
. The problem is, to get the queue started, I have to add .dequeue
outside the queue, which then forces tickerlistqueue
to start the next item in the queue. When you've got several Pusher calls coming in at once, this effectively renders the queue useless - the jobs just run over each other because that's exactly what I'm telling it to do.
Essentially what I need is to only run the .dequeue
line when the queue is empty. Otherwise, don't run that line, the queue will take care of itself.
var tickerlist = $('#ticker-list');
tickerlist.queue('tickerlistqueue', function(next) {
var name = 'John';
$(name).hide().prependTo('#ticker-list').slideDown(700, function () {
$('#ticker-list>div:last').remove();
next();
})
});
tickerlist.dequeue('tickerlistqueue'); //This is the only way to start the queue