Skip to content

Instantly share code, notes, and snippets.

@rustyJ4ck
Created June 4, 2014 12:51
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 rustyJ4ck/4dc84d83560cea478132 to your computer and use it in GitHub Desktop.
Save rustyJ4ck/4dc84d83560cea478132 to your computer and use it in GitHub Desktop.
(function(){
var _stop = false;
var id;
var i = 0;
function start() {
id = setInterval(task, 2000);
}
function stop() {
_stop = true;
console.log('stopped')
}
function task() {
if (_stop) {
clearInterval(id);
return false;
}
console.log(i++);
// do job
if (i > 2) {
stop();
}
}
start();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment