use raf to impl a more accurate timer and replay events async
This commit is contained in:
17
src/replay/timer.ts
Normal file
17
src/replay/timer.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
const FRAME_MS = 16;
|
||||
|
||||
function later(cb: () => void, delayMs: number) {
|
||||
const now = performance.now();
|
||||
|
||||
function check(step: number) {
|
||||
if (step - now > delayMs - FRAME_MS) {
|
||||
cb();
|
||||
} else {
|
||||
requestAnimationFrame(check);
|
||||
}
|
||||
}
|
||||
|
||||
requestAnimationFrame(check);
|
||||
}
|
||||
|
||||
export default later;
|
||||
Reference in New Issue
Block a user