Skip to content

Instantly share code, notes, and snippets.

@pleasetrythisathome
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pleasetrythisathome/d2dcffb3d9abe73f78a7 to your computer and use it in GitHub Desktop.
Save pleasetrythisathome/d2dcffb3d9abe73f78a7 to your computer and use it in GitHub Desktop.
Request Animation Frame Channel
(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