Created
March 22, 2012 09:47
-
-
Save rogercampos/2157400 to your computer and use it in GitHub Desktop.
Timed queue
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
// Use it like: | |
var myQueue = new TimedQueue(800); | |
// Call this 100 times in less than 500 ms: | |
myQueue.push(myCallback); | |
// myCallback function will be called only once, exactly 800 ms after the last call to 'push' |
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
var TimedQueue = function(timeout) { | |
var identifier = null; | |
this.push = function(callback) { | |
window.clearTimeout(identifier); | |
identifier = setTimeout(callback, timeout); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment