Skip to content

Instantly share code, notes, and snippets.

@fivetanley
Created March 12, 2012 23:47
Show Gist options
  • Save fivetanley/2025483 to your computer and use it in GitHub Desktop.
Save fivetanley/2025483 to your computer and use it in GitHub Desktop.
Queue and (this)
function Queue(delay){
this._lastExecutionTime = new Date();
this._delay = delay;
}
Queue.prototype.dequeue = function(){
//return first function in the list
};
Queue.prototype.execute = function(){
var lastExec = this._lastExecutionTime;
var currentExec = new Date();
var executionDiff = currentExec - lastExec;
if (executionDiff < this._delay){
setTimeout(this.execute, executionDiff);
//is setTimeout where "this" becomes window?
} else {
this.dequeue()();
if (this.getTasks.length() !== 0){
this.execute();
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment