Skip to content

Instantly share code, notes, and snippets.

Created May 22, 2011 21:33
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/985918 to your computer and use it in GitHub Desktop.
Save anonymous/985918 to your computer and use it in GitHub Desktop.
function IntervalMonitor() {
var intervals = [];
this.start = function (callback, repeat) {
var res = setInterval(callback, repeat);
intervals.push(res);
return res;
}
this.stop = function (item) {
for (var i in intervals) {
if (intervals[i] === item) {
intervals.splice(i, 1);
}
}
return clearInterval(item);
}
this.stopAll = function () {
intervals.forEach(function (i) {
clearInterval(i);
});
intervals = [];
}
}
var monitor = new IntervalMonitor();
var sandbox = { setInterval: monitor.start, clearInterval: monitor.stop };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment