Skip to content

Instantly share code, notes, and snippets.

@NoTimeForHero
Created March 4, 2012 23:14
Show Gist options
  • Save NoTimeForHero/1975302 to your computer and use it in GitHub Desktop.
Save NoTimeForHero/1975302 to your computer and use it in GitHub Desktop.
My simple Queue app with adder and executer
Queue = function(){
this.stopped = false;
this.array = [];
}
Queue.prototype = {
add: function(fn) { this.array.push(fn) },
pause: function() { this.stopped = true },
go: function() { this.stopped = false; this.exec(); },
exec: function() {
while(this.array.length>0) {
if (this.stopped==true) break;
(this.array.shift())(this);
}
}
}
qu = new Queue();
qu.add(function(){alert("One")});
qu.add(function(){alert("Two")});
qu.add(function(){
qu.pause();
setTimeout(function(){
alert("Three");
qu.go();
},3000);
});
qu.add(function(){alert("Four")});
qu.add(function(){
var queue = arguments[0];
queue.pause();
setTimeout(function(){
alert("Five");
queue.go();
},3000);
});
qu.add(function(){alert("Six")});
qu.exec();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment