Last active
August 29, 2015 14:05
-
-
Save pleasetrythisathome/d2dcffb3d9abe73f78a7 to your computer and use it in GitHub Desktop.
Request Animation Frame Channel
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
(defn animation-frame | |
"Return a channel which will close on the nth next animation frame." | |
([] (animation-frame 1)) | |
([n] (animation-frame n (async/chan 1))) | |
([n out] | |
(js/window.requestAnimationFrame | |
(fn [timestamp] | |
(if (= n 1) | |
(do | |
(async/put! out timestamp) | |
(async/close! out)) | |
(animation-frame (dec n) out)))) | |
out)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment