speedscope/utils.ts
2017-12-03 23:49:20 -08:00

13 lines
319 B
TypeScript

export function atMostOnceAFrame<F extends Function>(fn: F) {
let frameRequest: number | null = null
function ret(...args: any[]) {
if (frameRequest == null) {
frameRequest = requestAnimationFrame(function () {
fn(...args)
frameRequest = null
})
}
}
return ret as any as F
}