mirror of
https://github.com/oven-sh/setup-bun.git
synced 2025-07-18 04:28:28 +02:00
14 lines
310 B
TypeScript
14 lines
310 B
TypeScript
export function retry<T>(
|
|
fn: () => Promise<T>,
|
|
retries: number,
|
|
timeout = 5000
|
|
): Promise<T> {
|
|
return fn().catch((err) => {
|
|
if (retries <= 0) {
|
|
throw err;
|
|
}
|
|
return new Promise((resolve) => setTimeout(resolve, timeout)).then(() =>
|
|
retry(fn, retries - 1, timeout)
|
|
);
|
|
});
|
|
}
|