@loki/core
Advanced tools
Comparing version 0.28.0 to 0.29.0
{ | ||
"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" | ||
} |
@@ -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(() => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12002
328