@maz-ui/utils
Version:
Utils of maz-ui for JavaScript/TypeScript users
22 lines (21 loc) • 461 B
JavaScript
function i(o, n, r) {
const t = {};
return function(...c) {
t[o] || (t[o] = { timer: null, promise: null });
const e = t[o];
return e.timer && clearTimeout(e.timer), e.promise = new Promise((u, m) => {
e.timer = setTimeout(async () => {
try {
u(await n(...c));
} catch (s) {
m(s);
} finally {
delete t[o];
}
}, r);
}), e.promise;
};
}
export {
i as debounceId
};