UNPKG

@daimo/pay

Version:

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

45 lines (43 loc) 825 B
function startPolling({ key, intervalMs, pollFn, onResult, onError, log = console.log, debugMode = false }) { let active = true; let timer; const stop = () => { active = false; clearTimeout(timer); if (debugMode) { log(`[POLL] ${key} stopped`); } }; const tick = async () => { if (debugMode) { log(`[POLL] polling ${key}`); } try { const res = await pollFn(); if (!active) return; if (debugMode) { log(`[POLL] ${key} success`); } onResult(res); } catch (e) { if (!active) return; if (debugMode) { log(`[POLL] ${key} error: ${e}`); } onError(e); } timer = setTimeout(tick, intervalMs); }; tick(); return stop; } export { startPolling }; //# sourceMappingURL=polling.js.map