rwsdk
Version:
Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime
17 lines (16 loc) • 451 B
JavaScript
import { setTimeout } from "node:timers/promises";
const log = console.log;
export async function retry(fn, options) {
let lastError;
for (let i = 0; i < options.retries; i++) {
try {
return await fn();
}
catch (e) {
lastError = e;
log(`Attempt ${i + 1} failed. Retrying in ${options.delay}ms...`);
await setTimeout(options.delay);
}
}
throw lastError;
}