speedscope/utils.ts

13 lines
319 B
TypeScript
Raw Normal View History

2017-12-04 10:49:20 +03:00
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
}