ts-retry
ts-retry copied to clipboard
[Feature request] Get the last result when attempts are exhausted.
Something like this:
export async function retryAsync<T>(callback: () => Promise<T>, options: { max: number, until: (lastResult: T) => boolean }) {
let lastResult: T;
for (let i = 0; i < options.max; i++) {
lastResult = await callback();
if (!options.until(lastResult))
break;
}
return lastResult!;
}