Last active
August 29, 2015 14:17
-
-
Save nubunto/9822547b8d2196d6b9c7 to your computer and use it in GitHub Desktop.
simple and extensible time manipulation
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
| var time = (function() { | |
| var timeout = function(func, t) { | |
| function f() { | |
| // call the function and get the result | |
| var r = func.call(null); | |
| // should we recurse? | |
| if(r) setTimeout(f, t); | |
| } | |
| // schedule the first call | |
| setTimeout(f, t); | |
| } | |
| return { | |
| // how to implement a countdown from start and what to do when it ends. | |
| // pretty useful. | |
| countdown: function(start, fn) { | |
| timeout(function() { | |
| fn.call(null, start--); | |
| return start >= 0; | |
| }, 1000); | |
| }, | |
| timeout: timeout | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment