@lodestar/utils 1.16.0 → 1.17.0-dev.c999e4a353
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/retry.js +8 -2
- package/lib/retry.js.map +1 -1
- package/package.json +2 -2
package/lib/retry.js
CHANGED
|
@@ -7,10 +7,12 @@ import { sleep } from "./sleep.js";
|
|
|
7
7
|
*/
|
|
8
8
|
export async function retry(fn, opts) {
|
|
9
9
|
const maxRetries = opts?.retries ?? 5;
|
|
10
|
+
// Number of retries + the initial attempt
|
|
11
|
+
const maxAttempts = maxRetries + 1;
|
|
10
12
|
const shouldRetry = opts?.shouldRetry;
|
|
11
13
|
const onRetry = opts?.onRetry;
|
|
12
14
|
let lastError = Error("RetryError");
|
|
13
|
-
for (let i = 1; i <=
|
|
15
|
+
for (let i = 1; i <= maxAttempts; i++) {
|
|
14
16
|
try {
|
|
15
17
|
// If not the first attempt, invoke right before retrying
|
|
16
18
|
if (i > 1)
|
|
@@ -19,7 +21,11 @@ export async function retry(fn, opts) {
|
|
|
19
21
|
}
|
|
20
22
|
catch (e) {
|
|
21
23
|
lastError = e;
|
|
22
|
-
if (
|
|
24
|
+
if (i === maxAttempts) {
|
|
25
|
+
// Reached maximum number of attempts, there's no need to check if we should retry
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
else if (shouldRetry && !shouldRetry(lastError)) {
|
|
23
29
|
break;
|
|
24
30
|
}
|
|
25
31
|
else if (opts?.retryDelay !== undefined) {
|
package/lib/retry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAC;AA0BjC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAAI,EAAuC,EAAE,IAAmB;IACzF,MAAM,UAAU,GAAG,IAAI,EAAE,OAAO,IAAI,C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AE,UAAU,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;aAC7C;SACF;KACF;IACD,MAAM,SAAS,CAAC;AAClB,CAAC"}
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"bugs": {
|
|
12
12
|
"url": "https://github.com/ChainSafe/lodestar/issues"
|
|
13
13
|
},
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.17.0-dev.c999e4a353",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": "./lib/index.js",
|
|
17
17
|
"files": [
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"beacon",
|
|
59
59
|
"blockchain"
|
|
60
60
|
],
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "aaa50b1c046b7c3a82430a22664e42788f75d145"
|
|
62
62
|
}
|