1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-23 22:36:32 +02:00
Files
joplin/packages/tools/fuzzer/utils/retryWithCount.ts

22 lines
427 B
TypeScript

interface Options {
count: number;
onFail: (error: Error)=> Promise<void>;
}
const retryWithCount = async (task: ()=> Promise<void>, { count, onFail }: Options) => {
let lastError: Error|null = null;
for (let retry = 0; retry < count; retry ++) {
try {
return await task();
} catch (error) {
await onFail(error);
lastError = error;
}
}
if (lastError) throw lastError;
};
export default retryWithCount;