Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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