Skip to content

Instantly share code, notes, and snippets.

@RSNara
Created September 1, 2017 16:35
Show Gist options
  • Save RSNara/38b53e25f867a7298641b729c8c580ad to your computer and use it in GitHub Desktop.
Save RSNara/38b53e25f867a7298641b729c8c580ad to your computer and use it in GitHub Desktop.
A requestAnimationFrame loop that's useful as a game loop.
(defn raf-loop [func]
(let [stop (atom false)
id (atom nil)]
(reset! id (.requestAnimationFrame js/window
(fn helper [& args]
(when-not @stop
(reset! id (.requestAnimationFrame js/window helper))
(try
(apply func args)
(catch js/Error ex
(reset! stop true)
(throw ex)))))))
#(reset! stop true)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment