16 lines
343 B
JavaScript
16 lines
343 B
JavaScript
const timeouts = new Map();
|
|
|
|
export const debounce = (fn, delay) => {
|
|
const key = fn.toString();
|
|
if (!timeouts.get(key)) {
|
|
timeouts.set(key, setTimeout(async () => {
|
|
timeouts.delete(key);
|
|
await fn();
|
|
}, delay));
|
|
}
|
|
};
|
|
|
|
export const delay = async (ms) => {
|
|
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
};
|