UNPKG

@daysnap/utils

Version:
26 lines (22 loc) 562 B
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// 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; } } }; } exports.withPreventConsecutiveClicks = withPreventConsecutiveClicks;