Skip to content

Instantly share code, notes, and snippets.

@YuRen-tw
Created March 18, 2017 16:49
Show Gist options
  • Save YuRen-tw/a2695c454b0bd34a2d28dfa0192abfef to your computer and use it in GitHub Desktop.
Save YuRen-tw/a2695c454b0bd34a2d28dfa0192abfef to your computer and use it in GitHub Desktop.
Infinite Loop
function mkInfFuncToggle(func) {
var X = { x : 0 };
function infFunc() {
func();
if (X.x) { setTimeout(infFunc, 1); }
}
function infFuncToggle() {
if (X.x) { X.x = 0; }
else {
X.x = 1;
infFunc();
}
}
return infFuncToggle;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment