@dvcol/common-utils
Version:
Typescript library for common utility functions and constants
20 lines (19 loc) • 357 B
JavaScript
// lib/common/utils/timeout.util.ts
var useTimeout = (cb, delay) => {
let timeout;
const clear = () => clearTimeout(timeout);
return {
start: (...args) => {
clear();
timeout = setTimeout(() => cb(...args), delay);
},
immediate: (...args) => {
clear();
cb(...args);
},
clear
};
};
export {
useTimeout
};