@tldraw/utils
Version:
tldraw infinite canvas SDK (private utilities).
25 lines (24 loc) • 493 B
JavaScript
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();
} catch (e) {
if (matchError && !matchError(e)) throw e;
error = e;
await sleep(waitDuration);
}
}
throw error;
}
export {
retry
};
//# sourceMappingURL=retry.mjs.map