UNPKG

@maz-ui/utils

Version:

Utils of maz-ui for JavaScript/TypeScript users

20 lines (19 loc) 569 B
function c(s, o, t) { const l = {}; return async (...m) => { const a = Date.now(); return l[s] || (l[s] = { promise: null, lastCall: 0, lastArgs: [] }), a - l[s].lastCall >= t ? (l[s].lastCall = a, o(...m)) : (l[s].lastArgs = m, l[s].promise || (l[s].promise = new Promise((u) => { setTimeout( async () => { l[s].lastCall = Date.now(); const p = await o(...l[s].lastArgs); l[s].promise = null, u(p); }, t - (a - l[s].lastCall) ); })), l[s].promise); }; } export { c as throttleId };