Created
August 6, 2013 17:55
-
-
Save mlsteele/6166851 to your computer and use it in GitHub Desktop.
Helper class for managing the execution of javascript interval tasks.
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
| # (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