Skip to content

Instantly share code, notes, and snippets.

@Efreak
Forked from blackfyre/intervalManager.js
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Efreak/352856b7867a94d3b1ed to your computer and use it in GitHub Desktop.
Save Efreak/352856b7867a94d3b1ed to your computer and use it in GitHub Desktop.
/**
* Original by Zirak @ http://stackoverflow.com/a/8636050/1012431
*
* Had some issues with the clear function
*
* @type {{intervals: Array, make: make, clear: clear, clearAll: clearAll}}
*/
var interval = {
//to keep a reference to all the intervals
intervals : [],
//create another interval
make : function (fun, delay) {
var newKey = this.intervals.length +1;
this.intervals[newKey] = setInterval(fun,delay);
return newKey;
},
//clear a single interval
clear : function ( id ) {
clearInterval( this.intervals[id] );
delete this.intervals[id];
return true;
},
//clear all intervals
clearAll : function () {
for (var key in this.intervals) {
clearInterval(this.intervals[key]);
delete this.intervals[key];
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment