Created
March 12, 2012 23:47
-
-
Save fivetanley/2025483 to your computer and use it in GitHub Desktop.
Queue and (this)
This file contains hidden or 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
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