Created
June 18, 2014 15:48
-
-
Save pkqk/16ea2436101f7b3f9530 to your computer and use it in GitHub Desktop.
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 timeout(callback, wait) { | |
var cancel = window.setTimeout(callback, wait); | |
return function() { | |
window.clearTimeout(cancel); | |
} | |
} | |
cancel_the_timeout = timeout(function() { alert("hi") }, 3600); | |
cancel_the_timeout(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah that's a lovely pattern. I ended up slightly augmenting it to allow inspection of state from outside, as well as cancelling the timer.