watchdog
This commit is contained in:
parent
11109fcc62
commit
0a6d41ecf9
19
src/utils.ts
19
src/utils.ts
@ -135,7 +135,8 @@ export const throttleRAF = <T extends any[]>(
|
|||||||
let timerId: number | null = null;
|
let timerId: number | null = null;
|
||||||
let lastArgs: T | null = null;
|
let lastArgs: T | null = null;
|
||||||
let lastArgsTrailing: T | null = null;
|
let lastArgsTrailing: T | null = null;
|
||||||
|
let watchdog: NodeJS.Timeout | null = null;
|
||||||
|
|
||||||
const scheduleFunc = (args: T) => {
|
const scheduleFunc = (args: T) => {
|
||||||
timerId = window.requestAnimationFrame(() => {
|
timerId = window.requestAnimationFrame(() => {
|
||||||
timerId = null;
|
timerId = null;
|
||||||
@ -146,6 +147,9 @@ export const throttleRAF = <T extends any[]>(
|
|||||||
lastArgsTrailing = null;
|
lastArgsTrailing = null;
|
||||||
scheduleFunc(lastArgs);
|
scheduleFunc(lastArgs);
|
||||||
}
|
}
|
||||||
|
if (watchdog) {
|
||||||
|
clearTimout(watchdog);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -165,6 +169,9 @@ export const throttleRAF = <T extends any[]>(
|
|||||||
if (timerId !== null) {
|
if (timerId !== null) {
|
||||||
cancelAnimationFrame(timerId);
|
cancelAnimationFrame(timerId);
|
||||||
timerId = null;
|
timerId = null;
|
||||||
|
if (watchdog) {
|
||||||
|
clearTimout(watchdog);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (lastArgs) {
|
if (lastArgs) {
|
||||||
fn(...(lastArgsTrailing || lastArgs));
|
fn(...(lastArgsTrailing || lastArgs));
|
||||||
@ -176,8 +183,18 @@ export const throttleRAF = <T extends any[]>(
|
|||||||
if (timerId !== null) {
|
if (timerId !== null) {
|
||||||
cancelAnimationFrame(timerId);
|
cancelAnimationFrame(timerId);
|
||||||
timerId = null;
|
timerId = null;
|
||||||
|
if (watchdog) {
|
||||||
|
clearTimout(watchdog);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
watchdog = setTimeout(() => {
|
||||||
|
console.log("watchdog", timerId);
|
||||||
|
if (timerId !== null) {
|
||||||
|
cancelAnimationFrame(timerId);
|
||||||
|
timerId = null;
|
||||||
|
}
|
||||||
|
},1000);
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user