mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-01-23 02:36:05 +00:00
19 lines
510 B
TypeScript
19 lines
510 B
TypeScript
// avoids the performance issues caused by normal set interval, when the user
|
|
// is not at the computer for some time
|
|
export const lazySetInterval = (
|
|
func: () => void,
|
|
intervalDuration: number,
|
|
): (() => void) => {
|
|
let lastTimeoutId: ReturnType<typeof setTimeout>;
|
|
|
|
const interval = (): void => {
|
|
lastTimeoutId = setTimeout(interval, intervalDuration);
|
|
func.call(null);
|
|
};
|
|
|
|
lastTimeoutId = setTimeout(interval, intervalDuration);
|
|
|
|
return () => {
|
|
clearTimeout(lastTimeoutId);
|
|
};
|
|
};
|