UNPKG

rvx

Version:

A signal based rendering library

23 lines 597 B
export class PollTimeoutError extends Error { } export async function poll(fn, timeout) { const ac = new AbortController(); let timer; if (timeout !== undefined) { timer = setTimeout(() => ac.abort(new PollTimeoutError()), timeout); } try { for (;;) { const value = await fn(ac.signal); if (value) { return value; } ac.signal.throwIfAborted(); await new Promise(r => setTimeout(r, 0)); } } finally { clearTimeout(timer); } } //# sourceMappingURL=poll.js.map