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

This commit is contained in:
Yanzhen Yu
2018-10-12 14:30:44 +08:00
parent e93fd177be
commit f4bf94aa2d
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;