@dvcol/common-utils
Version:
Typescript library for common utility functions and constants
20 lines (17 loc) • 440 B
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true});// 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
};
};
exports.useTimeout = useTimeout;