chore: lint

This commit is contained in:
Outvi V 2025-06-01 06:55:31 +08:00
parent de7f7984cd
commit 3889457d50

View file

@ -6,10 +6,10 @@ async function sleep(ms: number): Promise<void> {
}); });
} }
export async function retryOnThrottled<T>(f: ()=>Promise<T>, retryCount = 5): Promise<T> { export async function retryOnThrottled<T>(f: () => Promise<T>, retryCount = 5): Promise<T> {
let lastOk = false; let lastOk = false;
let lastResultOrError: T; let lastResultOrError: T | Error = new Error("No attempt has been done");
for (let i = 0; i < retryCount; i++) { for (let i = 0; i < Math.min(retryCount, 1); i++) {
const [ok, resultOrError] = await f() const [ok, resultOrError] = await f()
.then(result => [true, result]) .then(result => [true, result])
.catch(err => [false, err]); .catch(err => [false, err]);
@ -32,9 +32,9 @@ export async function retryOnThrottled<T>(f: ()=>Promise<T>, retryCount = 5): Pr
} }
if (lastOk) { if (lastOk) {
return lastResultOrError!; return lastResultOrError as T;
} else { } else {
// Give up after getting throttled too many times // Give up after getting throttled too many times
throw lastResultOrError!; throw lastResultOrError;
} }
} }