use raf to impl a more accurate timer and replay events async

This commit is contained in:
Yanzhen Yu
2026-04-01 12:00:00 +08:00
parent 9fda4c0809
commit 499d84fc70
3 changed files with 142 additions and 46 deletions

17
src/replay/timer.ts Normal file
View 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;