mirror of https://github.com/mkrhere/pw2
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
385 B
16 lines
385 B
4 years ago
|
export const getTimeout = () => {
|
||
|
const clearables = new Set<number>();
|
||
|
|
||
|
const timeout = (f: (...attr: any[]) => any, t: number) => {
|
||
|
const self = setTimeout(() => (f(), clearables.delete(self)), t);
|
||
|
clearables.add(self);
|
||
|
};
|
||
|
|
||
|
const clearTimers = () => {
|
||
|
clearables.forEach(timer => clearTimeout(timer));
|
||
|
clearables.clear();
|
||
|
};
|
||
|
|
||
|
return [timeout, clearTimers] as const;
|
||
|
};
|