Skip to content

Instantly share code, notes, and snippets.

@thejefflarson
Created June 30, 2010 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thejefflarson/458946 to your computer and use it in GitHub Desktop.
Save thejefflarson/458946 to your computer and use it in GitHub Desktop.
propublica.models.AsyncFunctionQueue = propublica.Model.extend({
stopped : false,
init : function(attrs){
this.queue = [];
this._super(attrs);
},
add : function(fn){
this.queue.push(fn);
this._run();
},
start : function(){
this.stopped = false;
_.delay(_.bind(this._run, this), 50);
},
stop : function(){
this.stopped = true;
},
_run : function(){
if(!this.stopped && this.queue.length){
this.queue.shift()();
if(!this.stopped) this._run();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment