Last active
October 20, 2015 00:08
-
-
Save koozdra/497eb4f9b9119d85ca65 to your computer and use it in GitHub Desktop.
[SCRATCH] Cancellable Intermittent Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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