You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-26 17:03:12 +03:00
cleanup, return straight away
This commit is contained in:
13
src/utils.ts
13
src/utils.ts
@@ -752,17 +752,14 @@ export function getCrypto(): Object {
|
|||||||
|
|
||||||
export async function retryNetworkOperation(maxAttempts, callback) {
|
export async function retryNetworkOperation(maxAttempts, callback) {
|
||||||
let attempts = 0;
|
let attempts = 0;
|
||||||
let success = false;
|
|
||||||
let lastConnectionError = null;
|
let lastConnectionError = null;
|
||||||
let result;
|
while (attempts < maxAttempts) {
|
||||||
while (!success && attempts < maxAttempts) {
|
|
||||||
try {
|
try {
|
||||||
if (attempts > 0) {
|
if (attempts > 0) {
|
||||||
const timeout = 1000 * Math.pow(2, attempts);
|
const timeout = 1000 * Math.pow(2, attempts);
|
||||||
await new Promise(r => setTimeout(r, timeout));
|
await new Promise(r => setTimeout(r, timeout));
|
||||||
}
|
}
|
||||||
result = await callback();
|
return await callback();
|
||||||
success = true;
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err instanceof ConnectionError) {
|
if (err instanceof ConnectionError) {
|
||||||
attempts += 1;
|
attempts += 1;
|
||||||
@@ -772,9 +769,5 @@ export async function retryNetworkOperation(maxAttempts, callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!success) {
|
throw lastConnectionError;
|
||||||
throw lastConnectionError;
|
|
||||||
} else {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user