Skip to content

Instantly share code, notes, and snippets.

@gordonbrander
Created October 20, 2020 17:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gordonbrander/b1a404a522df7c1e4f9aa7eaa3a801dd to your computer and use it in GitHub Desktop.
Save gordonbrander/b1a404a522df7c1e4f9aa7eaa3a801dd to your computer and use it in GitHub Desktop.
FrameScheduler - a frame scheduler that will call callback at most once per frame.
// Creates a frame scheduler that will call callback at most once per frame.
export const FrameScheduler = callback => {
let isScheduled = false
const draw = t => {
isScheduled = false
callback(t)
}
const schedule = () => {
if (!isScheduled) {
isScheduled = true
requestAnimationFrame(draw)
}
}
return schedule
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment