Skip to content

Instantly share code, notes, and snippets.

@mlsteele
Created August 6, 2013 17:55
Show Gist options
  • Select an option

  • Save mlsteele/6166851 to your computer and use it in GitHub Desktop.

Select an option

Save mlsteele/6166851 to your computer and use it in GitHub Desktop.
Helper class for managing the execution of javascript interval tasks.
# (written for edX)
# Helper class for managing the execution of interval tasks.
# Handles pausing and restarting.
class IntervalManager
# Create a manager which will call `fn`
# after a call to .start every `ms` milliseconds.
constructor: (@ms, @fn) ->
@intervalID = null
# Start or restart firing every `ms` milliseconds.
# Soes not fire immediately.
start: ->
if @intervalID is null
@intervalID = setInterval @fn, @ms
# Pause firing.
stop: ->
clearInterval @intervalID
@intervalID = null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment