UNPKG

@daimo/pay

Version:

Seamless crypto payments. Onboard users from any chain, any coin into your app with one click.

36 lines (34 loc) 912 B
/** * Will poll the given function at the specified interval. Stops when the * returned handle is invoked. */ function startPolling({ key, intervalMs, pollFn, onResult, onError, log = console.log, }) { let active = true; let timer; const stop = () => { active = false; clearTimeout(timer); log(`[POLL] ${key} stopped`); }; const tick = async () => { log(`[POLL] polling ${key}`); try { const res = await pollFn(); if (!active) return; log(`[POLL] ${key} success`); onResult(res); } catch (e) { if (!active) return; log(`[POLL] ${key} error: ${e}`); onError(e); } timer = setTimeout(tick, intervalMs); }; tick(); return stop; } export { startPolling }; //# sourceMappingURL=polling.js.map