Skip to content

Instantly share code, notes, and snippets.

@mattsouth
Last active August 17, 2017 15:40
Show Gist options
  • Save mattsouth/055a6654e2e14ba0b3c1b8d806211c1c to your computer and use it in GitHub Desktop.
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.
class exports.Ticker
constructor: (timeout) ->
@timeout = timeout || 1000
_nextTick: =>
@tick = setTimeout(@_nextTick, @timeout)
console.log 'tick'
start: ->
@_nextTick()
stop: ->
clearTimeout @tick
console.log 'stopped'
@mattsouth
Copy link
Author

mattsouth commented Aug 17, 2017

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.

@mattsouth
Copy link
Author

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