set retry config defaults without supplying empty object

This commit is contained in:
Brent Schroeter 2026-02-07 06:49:01 +00:00
parent 463b0db759
commit 17225757d9

View file

@ -3,10 +3,10 @@
*/ */
export function withRetry<T extends unknown[], U>( export function withRetry<T extends unknown[], U>(
fn: (...args: T) => Promise<U>, fn: (...args: T) => Promise<U>,
{ attempts = 6, backoffMs = (attempt) => 1000 * 2 ** attempt }: { { attempts, backoffMs }: {
attempts: number; attempts: number;
backoffMs(attempt: number): number; backoffMs(attempt: number): number;
}, } = { attempts: 6, backoffMs: (attempt) => 1000 * 2 ** attempt },
): (...args: T) => Promise<U> { ): (...args: T) => Promise<U> {
return async (...args: T) => { return async (...args: T) => {
for (let attempt = 0; attempt < attempts - 1; attempt += 1) { for (let attempt = 0; attempt < attempts - 1; attempt += 1) {