UNPKG

@tldraw/utils

Version:

tldraw infinite canvas SDK (private utilities).

25 lines (24 loc) 549 B
import { sleep } from "./control.mjs"; async function retry(fn, { attempts = 3, waitDuration = 1e3, abortSignal, matchError } = {}) { let error = null; for (let i = 0; i < attempts; i++) { if (abortSignal?.aborted) throw new Error("aborted"); try { return await fn({ attempt: i, remaining: attempts - i, total: attempts }); } catch (e) { if (matchError && !matchError(e)) throw e; error = e; await sleep(waitDuration); } } throw error; } export { retry }; //# sourceMappingURL=retry.mjs.map