UNPKG

@daysnap/utils

Version:
26 lines (24 loc) 461 B
// src/withPreventConsecutiveClicks.ts function withPreventConsecutiveClicks(fn, ms) { let flag = false; return async function(...args) { if (flag) { return; } flag = true; try { return await fn.apply(this, args); } catch (err) { throw err; } finally { if (ms) { setTimeout(() => flag = false, ms); } else { flag = false; } } }; } export { withPreventConsecutiveClicks };