@requestnetwork/utils 0.36.1-next.1885 → 0.36.1-next.1887
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/dist/retry.d.ts +5 -1
- package/dist/retry.d.ts.map +1 -1
- package/dist/retry.js +9 -2
- package/dist/retry.js.map +1 -1
- package/package.json +3 -3
package/dist/retry.d.ts
CHANGED
|
@@ -6,11 +6,15 @@
|
|
|
6
6
|
* @param [options.context] The context to run the function
|
|
7
7
|
* @param [options.maxRetries=DEFAULT_MAX_RETRIES] The maximum amount of retries for the function
|
|
8
8
|
* @param [options.retryDelay=DEFAULT_RETRY_DELAY] The delay between retries
|
|
9
|
+
* @param [options.exponentialBackoffDelay=DEFAULT_EXPONENTIAL_BACKOFF_DELAY] The exponential backoff delay increment
|
|
10
|
+
* @param [options.maxExponentialBackoffDelay=DEFAULT_MAX_EXPONENTIAL_BACKOFF_DELAY] The maximum exponential backoff delay allowed
|
|
9
11
|
*/
|
|
10
|
-
declare const retry: <TParams extends unknown[], TReturn>(target: (...params: TParams) => TReturn | Promise<TReturn>, { context, maxRetries, retryDelay, }?: {
|
|
12
|
+
declare const retry: <TParams extends unknown[], TReturn>(target: (...params: TParams) => TReturn | Promise<TReturn>, { context, maxRetries, retryDelay, exponentialBackoffDelay, maxExponentialBackoffDelay, }?: {
|
|
11
13
|
context?: unknown;
|
|
12
14
|
maxRetries?: number | undefined;
|
|
13
15
|
retryDelay?: number | undefined;
|
|
16
|
+
exponentialBackoffDelay?: number | undefined;
|
|
17
|
+
maxExponentialBackoffDelay?: number | undefined;
|
|
14
18
|
}) => (...params: TParams) => Promise<TReturn>;
|
|
15
19
|
export { retry };
|
|
16
20
|
//# sourceMappingURL=retry.d.ts.map
|
package/dist/retry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAYA;;;;;;;;;;GAUG;AACH,QAAA,MAAM,KAAK;;;;;;8CAoDV,CAAC;AAEF,OAAO,EAAE,KAAK,EAAE,CAAC"}
|
package/dist/retry.js
CHANGED
|
@@ -6,6 +6,10 @@ const tslib_1 = require("tslib");
|
|
|
6
6
|
const DEFAULT_MAX_RETRIES = 5;
|
|
7
7
|
// Default delay between retries
|
|
8
8
|
const DEFAULT_RETRY_DELAY = 100;
|
|
9
|
+
// Default exponential backoff delay increment
|
|
10
|
+
const DEFAULT_EXPONENTIAL_BACKOFF_DELAY = 0;
|
|
11
|
+
// Maximum exponential backoff delay allowed
|
|
12
|
+
const DEFAULT_MAX_EXPONENTIAL_BACKOFF_DELAY = 30000;
|
|
9
13
|
/**
|
|
10
14
|
* A method that retries a function a defined amount of times if it fails.
|
|
11
15
|
*
|
|
@@ -14,8 +18,10 @@ const DEFAULT_RETRY_DELAY = 100;
|
|
|
14
18
|
* @param [options.context] The context to run the function
|
|
15
19
|
* @param [options.maxRetries=DEFAULT_MAX_RETRIES] The maximum amount of retries for the function
|
|
16
20
|
* @param [options.retryDelay=DEFAULT_RETRY_DELAY] The delay between retries
|
|
21
|
+
* @param [options.exponentialBackoffDelay=DEFAULT_EXPONENTIAL_BACKOFF_DELAY] The exponential backoff delay increment
|
|
22
|
+
* @param [options.maxExponentialBackoffDelay=DEFAULT_MAX_EXPONENTIAL_BACKOFF_DELAY] The maximum exponential backoff delay allowed
|
|
17
23
|
*/
|
|
18
|
-
const retry = (target, { context, maxRetries = DEFAULT_MAX_RETRIES, retryDelay = DEFAULT_RETRY_DELAY, } = {}) => {
|
|
24
|
+
const retry = (target, { context, maxRetries = DEFAULT_MAX_RETRIES, retryDelay = DEFAULT_RETRY_DELAY, exponentialBackoffDelay = DEFAULT_EXPONENTIAL_BACKOFF_DELAY, maxExponentialBackoffDelay = DEFAULT_MAX_EXPONENTIAL_BACKOFF_DELAY, } = {}) => {
|
|
19
25
|
// If a context was passed in, bind it to to the target function
|
|
20
26
|
if (context) {
|
|
21
27
|
target = target.bind(context);
|
|
@@ -36,7 +42,8 @@ const retry = (target, { context, maxRetries = DEFAULT_MAX_RETRIES, retryDelay =
|
|
|
36
42
|
if (retry < maxRetries) {
|
|
37
43
|
retry++;
|
|
38
44
|
// Wait for the delay before retrying
|
|
39
|
-
yield new Promise((resolve) => setTimeout(resolve, retryDelay
|
|
45
|
+
yield new Promise((resolve) => setTimeout(resolve, retryDelay +
|
|
46
|
+
Math.min(maxExponentialBackoffDelay, exponentialBackoffDelay * Math.pow(2, retry))));
|
|
40
47
|
return retryFunction(...innerArgs);
|
|
41
48
|
}
|
|
42
49
|
else {
|
package/dist/retry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":";;;;AAAA,4BAA4B;AAC5B,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAE9B,gCAAgC;AAChC,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAEhC
|
|
1
|
+
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":";;;;AAAA,4BAA4B;AAC5B,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAE9B,gCAAgC;AAChC,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAEhC,8CAA8C;AAC9C,MAAM,iCAAiC,GAAG,CAAC,CAAC;AAE5C,4CAA4C;AAC5C,MAAM,qCAAqC,GAAG,KAAK,CAAC;AAEpD;;;;;;;;;;GAUG;AACH,MAAM,KAAK,GAAG,CACZ,MAA0D,EAC1D,EACE,OAAO,EACP,UAAU,GAAG,mBAAmB,EAChC,UAAU,GAAG,mBAAmB,EAChC,uBAAuB,GAAG,iCAAiC,EAC3D,0BAA0B,GAAG,qCAAqC,MAOhE,EAAE,EACsC,EAAE;IAC9C,gEAAgE;IAChE,IAAI,OAAO,EAAE;QACX,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;KAC/B;IAED,mEAAmE;IACnE,OAAO,CAAO,GAAG,IAAa,EAAoB,EAAE;QAClD,gCAAgC;QAChC,IAAI,KAAK,GAAG,CAAC,CAAC;QAEd,mDAAmD;QACnD,OAAO,CAAC,SAAe,aAAa,CAAC,GAAG,SAAkB;;gBACxD,IAAI;oBACF,6DAA6D;oBAC7D,OAAO,MAAM,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC;iBACnC;gBAAC,OAAO,CAAC,EAAE;oBACV,4DAA4D;oBAC5D,IAAI,KAAK,GAAG,UAAU,EAAE;wBACtB,KAAK,EAAE,CAAC;wBACR,qCAAqC;wBACrC,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAC5B,UAAU,CACR,OAAO,EACP,UAAU;4BACR,IAAI,CAAC,GAAG,CAAC,0BAA0B,EAAE,uBAAuB,GAAG,SAAA,CAAC,EAAI,KAAK,CAAA,CAAC,CAC7E,CACF,CAAC;wBAEF,OAAO,aAAa,CAAC,GAAG,SAAS,CAAC,CAAC;qBACpC;yBAAM;wBACL,0CAA0C;wBAC1C,MAAM,CAAC,CAAC;qBACT;iBACF;YACH,CAAC;SAAA,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IACd,CAAC,CAAA,CAAC;AACJ,CAAC,CAAC;AAEO,sBAAK"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@requestnetwork/utils",
|
|
3
|
-
"version": "0.36.1-next.
|
|
3
|
+
"version": "0.36.1-next.1887+6ac8c287",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@rainbow-me/fee-suggestions": "2.1.0",
|
|
44
|
-
"@requestnetwork/types": "0.36.1-next.
|
|
44
|
+
"@requestnetwork/types": "0.36.1-next.1887+6ac8c287",
|
|
45
45
|
"eccrypto": "1.1.6",
|
|
46
46
|
"ethers": "5.5.1",
|
|
47
47
|
"secp256k1": "4.0.2",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"ts-node": "10.9.1",
|
|
58
58
|
"typescript": "4.9.5"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "6ac8c287b8838af93e9384bc30352b334dba116a"
|
|
61
61
|
}
|