Skip to content

Instantly share code, notes, and snippets.

@renepardon
Created April 30, 2012 16:43
Show Gist options
  • Save renepardon/2559934 to your computer and use it in GitHub Desktop.
Save renepardon/2559934 to your computer and use it in GitHub Desktop.
For those who need a queue for different reasons ;)
// Initializations.
var theQueue = $({});
var elements = [1, 2, 3, 4, 5, 6];
// Loop through all elements and add a function to the stack for every element.
$.each(elements, function(index, item)
{
theQueue.queue('stack', function(next)
{
// Do some processing here..
console.log('item: ' + item);
setTimeout(function() { next(); }, 1000);
});
});
// Executes every function within the stack after excactly one second.
theQueue.dequeue('stack');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment