mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-08 04:54:32 +00:00
chore: lint
This commit is contained in:
parent
de7f7984cd
commit
3889457d50
1 changed files with 6 additions and 6 deletions
|
@ -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 lastResultOrError: T;
|
||||
for (let i = 0; i < retryCount; i++) {
|
||||
let lastResultOrError: T | Error = new Error("No attempt has been done");
|
||||
for (let i = 0; i < Math.min(retryCount, 1); i++) {
|
||||
const [ok, resultOrError] = await f()
|
||||
.then(result => [true, result])
|
||||
.catch(err => [false, err]);
|
||||
|
@ -32,9 +32,9 @@ export async function retryOnThrottled<T>(f: ()=>Promise<T>, retryCount = 5): Pr
|
|||
}
|
||||
|
||||
if (lastOk) {
|
||||
return lastResultOrError!;
|
||||
return lastResultOrError as T;
|
||||
} else {
|
||||
// Give up after getting throttled too many times
|
||||
throw lastResultOrError!;
|
||||
throw lastResultOrError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue