mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
watchdog
This commit is contained in:
parent
11109fcc62
commit
0a6d41ecf9
1 changed files with 18 additions and 1 deletions
19
src/utils.ts
19
src/utils.ts
|
@ -135,7 +135,8 @@ export const throttleRAF = <T extends any[]>(
|
|||
let timerId: number | null = null;
|
||||
let lastArgs: T | null = null;
|
||||
let lastArgsTrailing: T | null = null;
|
||||
|
||||
let watchdog: NodeJS.Timeout | null = null;
|
||||
|
||||
const scheduleFunc = (args: T) => {
|
||||
timerId = window.requestAnimationFrame(() => {
|
||||
timerId = null;
|
||||
|
@ -146,6 +147,9 @@ export const throttleRAF = <T extends any[]>(
|
|||
lastArgsTrailing = null;
|
||||
scheduleFunc(lastArgs);
|
||||
}
|
||||
if (watchdog) {
|
||||
clearTimout(watchdog);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -165,6 +169,9 @@ export const throttleRAF = <T extends any[]>(
|
|||
if (timerId !== null) {
|
||||
cancelAnimationFrame(timerId);
|
||||
timerId = null;
|
||||
if (watchdog) {
|
||||
clearTimout(watchdog);
|
||||
}
|
||||
}
|
||||
if (lastArgs) {
|
||||
fn(...(lastArgsTrailing || lastArgs));
|
||||
|
@ -176,8 +183,18 @@ export const throttleRAF = <T extends any[]>(
|
|||
if (timerId !== null) {
|
||||
cancelAnimationFrame(timerId);
|
||||
timerId = null;
|
||||
if (watchdog) {
|
||||
clearTimout(watchdog);
|
||||
}
|
||||
}
|
||||
};
|
||||
watchdog = setTimeout(() => {
|
||||
console.log("watchdog", timerId);
|
||||
if (timerId !== null) {
|
||||
cancelAnimationFrame(timerId);
|
||||
timerId = null;
|
||||
}
|
||||
},1000);
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue