feat: add timeout

This commit is contained in:
Jozef Steinhübl 2024-04-02 12:16:10 +02:00
parent ce0497c083
commit 132a13a140
2 changed files with 9 additions and 3 deletions

2
dist/setup/index.js generated vendored

File diff suppressed because one or more lines are too long

View file

@ -1,8 +1,14 @@
export function retry<T>(fn: () => Promise<T>, retries: number): Promise<T> { export function retry<T>(
fn: () => Promise<T>,
retries: number,
timeout = 5000
): Promise<T> {
return fn().catch((err) => { return fn().catch((err) => {
if (retries <= 0) { if (retries <= 0) {
throw err; throw err;
} }
return retry(fn, retries - 1); return new Promise((resolve) => setTimeout(resolve, timeout)).then(() =>
retry(fn, retries - 1, timeout)
);
}); });
} }