Last active
August 17, 2017 15:40
-
-
Save mattsouth/055a6654e2e14ba0b3c1b8d806211c1c to your computer and use it in GitHub Desktop.
In your REPL of choice you can create a ticker and then start and stop it at will.
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
class exports.Ticker | |
constructor: (timeout) -> | |
@timeout = timeout || 1000 | |
_nextTick: => | |
@tick = setTimeout(@_nextTick, @timeout) | |
console.log 'tick' | |
start: -> | |
@_nextTick() | |
stop: -> | |
clearTimeout @tick | |
console.log 'stopped' |
Similarly, in both the coffee and node REPL you can set a ticking ticker equal to undefined and it will continue ticking, though again, you will no longer be able to stop it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
But while a ticker is ticking the coffee REPL wont close normally. The node REPL will exit normally when a ticker is ticking. In the coffee REPL, pressing [ctrl][D] doesnt close the REPL though you wont have any access to your ticker anymore to stop it ticking. You'll have to [ctrl][C] to exit.