Created
June 30, 2010 17:06
-
-
Save thejefflarson/458946 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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