Skip to content

Instantly share code, notes, and snippets.

@DannyDelott
Last active March 13, 2017 13:31
Show Gist options
  • Save DannyDelott/56d605d5870dede6663f to your computer and use it in GitHub Desktop.
Save DannyDelott/56d605d5870dede6663f to your computer and use it in GitHub Desktop.
Use a recursive setTimeout instead of setInterval
var betterInterval = function(execute, delay, reverse) {
execute.stop = false;
execute.stopped = false;
if(reverse){ execute(); }
(function subroutine() {
setTimeout(function() {
if(!execute.stop){
execute();
subroutine();
}else{ execute.stopped = true; }
}, delay);
})();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment