Permalink
Fetching contributors…
Cannot retrieve contributors at this time
20 lines (19 sloc) 350 Bytes
export function retryOnReject<T>(
f: () => T | Promise<T>,
maxRetries: number
): Promise<T> {
let retries = 0
const g: () => Promise<T> = async () => {
try {
return await f()
} catch (err) {
if (retries < maxRetries) {
retries++
return g()
} else {
throw err
}
}
}
return g()
}