Skip to content

Instantly share code, notes, and snippets.

@koozdra
Last active October 20, 2015 00:08
Show Gist options
  • Save koozdra/497eb4f9b9119d85ca65 to your computer and use it in GitHub Desktop.
Save koozdra/497eb4f9b9119d85ca65 to your computer and use it in GitHub Desktop.
[SCRATCH] Cancellable Intermittent Function
function animate(fn) {
var halted = false;
var f = function() {
fn();
if (!halted) requestAnimationFrame(f);
}
f();
return {
halt: function() {
halted = true;
}
}
}
var control = animate(function() {
console.log('yes');
});
setTimeout(function() {
control.halt();
}, 1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment