dao-governance-framework/forum-network/public/util.js

18 lines
354 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);
});
};