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.
15 lines
292 B
15 lines
292 B
5 years ago
|
export const getTimeout = () => {
|
||
|
const set = new Set();
|
||
|
|
||
|
const timeout = (f, t) => {
|
||
|
const self = set.add(setTimeout(() => (f(), set.delete(self)), t));
|
||
|
};
|
||
|
|
||
|
const clearTimers = () => {
|
||
|
set.forEach(timer => clearTimeout(timer));
|
||
|
set.clear();
|
||
|
};
|
||
|
|
||
|
return [timeout, clearTimers];
|
||
|
};
|