@augment-vir/common 31.46.1 → 31.48.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.
|
@@ -24,7 +24,9 @@ import { type IsEqual } from 'type-fest';
|
|
|
24
24
|
*
|
|
25
25
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
26
26
|
*/
|
|
27
|
-
export declare function retry<const T, const Duration extends AtLeastOneDuration | undefined = undefined>(maxRetries: number, callback: (
|
|
27
|
+
export declare function retry<const T, const Duration extends AtLeastOneDuration | undefined = undefined>(maxRetries: number, callback: (
|
|
28
|
+
/** This will be `0` for the first execution, then increment with each retry. */
|
|
29
|
+
retryCount: number) => T, options?: PartialWithUndefined<{
|
|
28
30
|
/**
|
|
29
31
|
* Wait this duration between each retry.
|
|
30
32
|
*
|
|
@@ -23,18 +23,21 @@ import { ensureErrorAndPrependMessage, wait } from '@augment-vir/core';
|
|
|
23
23
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
24
24
|
*/
|
|
25
25
|
export function retry(maxRetries, callback, options = {}) {
|
|
26
|
+
return internalRetry(0, maxRetries, callback, options);
|
|
27
|
+
}
|
|
28
|
+
function internalRetry(currentRetry, maxRetries, callback, options = {}) {
|
|
26
29
|
try {
|
|
27
|
-
const result = callback();
|
|
30
|
+
const result = callback(currentRetry);
|
|
28
31
|
if (result instanceof Promise) {
|
|
29
32
|
return result.catch(async (error) => {
|
|
30
|
-
if (
|
|
33
|
+
if (currentRetry >= maxRetries) {
|
|
31
34
|
throw ensureErrorAndPrependMessage(error, 'Retry max reached');
|
|
32
35
|
}
|
|
33
36
|
else {
|
|
34
37
|
if (options.interval) {
|
|
35
38
|
await wait(options.interval);
|
|
36
39
|
}
|
|
37
|
-
return
|
|
40
|
+
return internalRetry(currentRetry + 1, maxRetries, callback, options);
|
|
38
41
|
}
|
|
39
42
|
});
|
|
40
43
|
}
|
|
@@ -43,14 +46,14 @@ export function retry(maxRetries, callback, options = {}) {
|
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
48
|
catch (error) {
|
|
46
|
-
if (
|
|
49
|
+
if (currentRetry >= maxRetries) {
|
|
47
50
|
throw ensureErrorAndPrependMessage(error, 'Retry max reached');
|
|
48
51
|
}
|
|
49
52
|
else if (options.interval) {
|
|
50
|
-
return wait(options.interval).then(() =>
|
|
53
|
+
return wait(options.interval).then(() => internalRetry(currentRetry + 1, maxRetries, callback, options));
|
|
51
54
|
}
|
|
52
55
|
else {
|
|
53
|
-
return
|
|
56
|
+
return internalRetry(currentRetry + 1, maxRetries, callback, options);
|
|
54
57
|
}
|
|
55
58
|
}
|
|
56
59
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@augment-vir/common",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.48.0",
|
|
4
4
|
"description": "A collection of augments, helpers types, functions, and classes for any JavaScript environment.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"augment",
|
|
@@ -40,13 +40,13 @@
|
|
|
40
40
|
"test:web": "virmator --no-deps test web"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@augment-vir/assert": "^31.
|
|
44
|
-
"@augment-vir/core": "^31.
|
|
43
|
+
"@augment-vir/assert": "^31.48.0",
|
|
44
|
+
"@augment-vir/core": "^31.48.0",
|
|
45
45
|
"@date-vir/duration": "^8.0.0",
|
|
46
46
|
"ansi-styles": "^6.2.3",
|
|
47
47
|
"deepcopy-esm": "^2.1.1",
|
|
48
48
|
"json5": "^2.2.3",
|
|
49
|
-
"type-fest": "^5.
|
|
49
|
+
"type-fest": "^5.2.0",
|
|
50
50
|
"typed-event-target": "^4.1.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|