mauss
Version:
lightweight, modular, type-safe utilities
16 lines (15 loc) • 408 B
JavaScript
const DURATION = 300;
export function debounce(fn, time = DURATION) {
let timeout;
return async (...args) => {
if (timeout)
clearTimeout(timeout);
await new Promise((fulfil) => {
timeout = setTimeout(fulfil, time);
});
return fn(...args);
};
}
export async function pause(ms) {
return new Promise((fulfil) => setTimeout(fulfil, ms));
}