From 30101a4428c606cadb7818fb128b79434a14d277 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 23 Apr 2020 15:22:46 +0200 Subject: [PATCH] cleanup, return straight away --- src/utils.ts | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 684495af0..124ed0f96 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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; }