export async function retry any>( fn: T, maxTry: number = 5, retryCount = 1 ): Promise>> { const currRetry = typeof retryCount === "number" ? retryCount : 1 try { const result = await fn() return result } catch (e) { console.log(`Retry ${currRetry} failed.`) if (currRetry > maxTry) { console.log(`All ${maxTry} retry attempts exhausted`) throw e } return retry(fn, maxTry, currRetry + 1) } }