@loki/core
Advanced tools
+2
-2
| { | ||
| "name": "@loki/core", | ||
| "version": "0.28.0", | ||
| "version": "0.29.0", | ||
| "description": "Loki Chrome target core lib", | ||
@@ -28,3 +28,3 @@ "keywords": [ | ||
| }, | ||
| "gitHead": "6cbab143b2367fbf4dddca561c593257c503ff11" | ||
| "gitHead": "4be00352e8554d7aff69c49f670fc247a9d22e6e" | ||
| } |
+24
-23
@@ -34,27 +34,28 @@ const { TimeoutError } = require('./errors'); | ||
| const withRetries = (maxRetries = 3, backoff = 0) => (fn) => async ( | ||
| ...args | ||
| ) => { | ||
| let tries = 0; | ||
| let lastError; | ||
| while (tries <= maxRetries) { | ||
| tries++; | ||
| try { | ||
| const result = await fn(...args); | ||
| return result; | ||
| } catch (err) { | ||
| lastError = err; | ||
| const withRetries = | ||
| (maxRetries = 3, backoff = 0) => | ||
| (fn) => | ||
| async (...args) => { | ||
| let tries = 0; | ||
| let lastError; | ||
| while (tries <= maxRetries) { | ||
| tries++; | ||
| try { | ||
| const result = await fn(...args); | ||
| return result; | ||
| } catch (err) { | ||
| lastError = err; | ||
| } | ||
| if (backoff && tries <= maxRetries) { | ||
| await sleep(backoff); | ||
| } | ||
| } | ||
| if (backoff && tries <= maxRetries) { | ||
| await sleep(backoff); | ||
| if (tries === 1) { | ||
| throw lastError; | ||
| } | ||
| } | ||
| if (tries === 1) { | ||
| throw lastError; | ||
| } | ||
| const message = lastError.message || lastError.toString(); | ||
| const error = new Error(`Failed with "${message}" after ${tries} tries`); | ||
| error.originalError = lastError; | ||
| throw error; | ||
| }; | ||
| const message = lastError.message || lastError.toString(); | ||
| const error = new Error(`Failed with "${message}" after ${tries} tries`); | ||
| error.originalError = lastError; | ||
| throw error; | ||
| }; | ||
@@ -61,0 +62,0 @@ function unwrapError(rawError) { |
@@ -29,3 +29,3 @@ const { withRetries } = require('./failure-handling'); | ||
| const retries = 3; | ||
| jest.useFakeTimers(); | ||
| jest.useFakeTimers('legacy'); | ||
| const callback = jest.fn(); | ||
@@ -32,0 +32,0 @@ const mockFn = jest.fn(() => { |
12002
0.45%328
0.31%