mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-08 13:04:34 +00:00
chore: lint
This commit is contained in:
parent
de7f7984cd
commit
3889457d50
1 changed files with 6 additions and 6 deletions
|
@ -8,8 +8,8 @@ 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue