Created
July 2, 2014 13:29
-
-
Save stevenpetryk/7bcca052dc576f032380 to your computer and use it in GitHub Desktop.
This is quite a useful improvement over the regular Javascript setInterval()
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
# Usage: | |
# every 250, (stop) -> | |
# stop() if condition | |
# # some logic... | |
# | |
# Still preserves original behavior if you want to do that: | |
# interval_id = every 250, someFunction | |
# clearInterval(interval_id) | |
every = (time, fn) -> | |
stop = -> clearInterval(interval_id) | |
helper = -> fn(stop) | |
interval_id = setInterval(helper, time) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment