1
0
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:
Bruno Windels
2020-04-23 15:22:46 +02:00
parent 668e8f6f24
commit 30101a4428

View File

@@ -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;
}
} }