cleanup, return straight away
This commit is contained in:
+3
-10
@@ -752,17 +752,14 @@ export function getCrypto(): Object {
|
||||
|
||||
export async function retryNetworkOperation(maxAttempts, callback) {
|
||||
let attempts = 0;
|
||||
let success = false;
|
||||
let lastConnectionError = null;
|
||||
let result;
|
||||
while (!success && attempts < maxAttempts) {
|
||||
while (attempts < maxAttempts) {
|
||||
try {
|
||||
if (attempts > 0) {
|
||||
const timeout = 1000 * Math.pow(2, attempts);
|
||||
await new Promise(r => setTimeout(r, timeout));
|
||||
}
|
||||
result = await callback();
|
||||
success = true;
|
||||
return await callback();
|
||||
} catch (err) {
|
||||
if (err instanceof ConnectionError) {
|
||||
attempts += 1;
|
||||
@@ -772,9 +769,5 @@ export async function retryNetworkOperation(maxAttempts, callback) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!success) {
|
||||
throw lastConnectionError;
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
throw lastConnectionError;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user