Skip to content

Instantly share code, notes, and snippets.

@antonagestam
Last active December 8, 2018 01:07
Show Gist options
  • Save antonagestam/b78df0cda2043b63a625a2985091c79d to your computer and use it in GitHub Desktop.
Save antonagestam/b78df0cda2043b63a625a2985091c79d to your computer and use it in GitHub Desktop.
Asynchronous animation loop
/*
A slightly more condensed version of https://esdiscuss.org/topic/promises-async-functions-and-requestanimationframe-together
*/
let animation_frame = () => new Promise(window.requestAnimationFrame);
(async () => {
while (true) {
await animation_frame();
// draw
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment