import { delay } from './delay'; export async function retry( fn: () => Promise, opts?: { attempts?: number; wait?: number; log?: (msg: string, obj: object) => void }, ): Promise { const { attempts = 3, wait = 15 * 1000, log } = opts || {}; let attempt = 0; // eslint-disable-next-line no-constant-condition while (true) { try { return await fn(); } catch (e: any) { (log || console.debug)(`Attempt (${attempt}/${attempts}):`, { error: e }); if (attempt >= attempts) { throw e; } attempt++; await delay(wait); } } }