@lodestar/utils 1.16.0-rc.0 → 1.16.0
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.d.ts +9 -3
- package/lib/retry.js +4 -0
- package/lib/retry.js.map +1 -1
- package/package.json +2 -2
package/lib/retry.d.ts
CHANGED
|
@@ -4,11 +4,17 @@ export type RetryOptions = {
|
|
|
4
4
|
*/
|
|
5
5
|
retries?: number;
|
|
6
6
|
/**
|
|
7
|
-
* An optional Function that is invoked after the provided callback throws
|
|
8
|
-
* It expects a boolean to know if it should retry or not
|
|
9
|
-
* Useful to make retrying conditional on the type of error thrown
|
|
7
|
+
* An optional Function that is invoked after the provided callback throws.
|
|
8
|
+
* It expects a boolean to know if it should retry or not.
|
|
9
|
+
* Useful to make retrying conditional on the type of error thrown.
|
|
10
10
|
*/
|
|
11
11
|
shouldRetry?: (lastError: Error) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* An optional Function that is invoked right before a retry is performed.
|
|
14
|
+
* It's passed the Error that triggered it and a number identifying the attempt.
|
|
15
|
+
* Useful to track number of retries and errors in logs or metrics.
|
|
16
|
+
*/
|
|
17
|
+
onRetry?: (lastError: Error, attempt: number) => unknown;
|
|
12
18
|
/**
|
|
13
19
|
* Milliseconds to wait before retrying again
|
|
14
20
|
*/
|
package/lib/retry.js
CHANGED
|
@@ -8,9 +8,13 @@ import { sleep } from "./sleep.js";
|
|
|
8
8
|
export async function retry(fn, opts) {
|
|
9
9
|
const maxRetries = opts?.retries ?? 5;
|
|
10
10
|
const shouldRetry = opts?.shouldRetry;
|
|
11
|
+
const onRetry = opts?.onRetry;
|
|
11
12
|
let lastError = Error("RetryError");
|
|
12
13
|
for (let i = 1; i <= maxRetries; i++) {
|
|
13
14
|
try {
|
|
15
|
+
// If not the first attempt, invoke right before retrying
|
|
16
|
+
if (i > 1)
|
|
17
|
+
onRetry?.(lastError, i);
|
|
14
18
|
return await fn(i);
|
|
15
19
|
}
|
|
16
20
|
catch (e) {
|
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;
|
|
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,CAAC,CAAC;IACtC,MAAM,WAAW,GAAG,IAAI,EAAE,WAAW,CAAC;IACtC,MAAM,OAAO,GAAG,IAAI,EAAE,OAAO,CAAC;IAE9B,IAAI,SAAS,GAAU,KAAK,CAAC,YAAY,CAAC,CAAC;IAC3C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,UAAU,EAAE,CAAC,EAAE,EAAE;QACpC,IAAI;YACF,yDAAyD;YACzD,IAAI,CAAC,GAAG,CAAC;gBAAE,OAAO,EAAE,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;YAEnC,OAAO,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;SACpB;QAAC,OAAO,CAAC,EAAE;YACV,SAAS,GAAG,CAAU,CAAC;YACvB,IAAI,WAAW,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE;gBAC1C,MAAM;aACP;iBAAM,IAAI,IAAI,EAAE,UAAU,KAAK,SAAS,EAAE;gBACzC,MAAM,KAAK,CAAC,IAAI,EAAE,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.16.0
|
|
14
|
+
"version": "1.16.0",
|
|
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": "14ea6549b08c0375b0f1167413474627fdbcbf66"
|
|
62
62
|
}
|