@augment-vir/common 31.50.3 → 31.51.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.
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
import { type PartialWithUndefined } from '@augment-vir/common';
|
|
2
2
|
import { type AtLeastOneDuration } from '@date-vir/duration';
|
|
3
3
|
import { type IsEqual } from 'type-fest';
|
|
4
|
+
/**
|
|
5
|
+
* Params for the callback passed to {@link retry}.
|
|
6
|
+
*
|
|
7
|
+
* @category Internal
|
|
8
|
+
* @category Package : @augment-vir/common
|
|
9
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
10
|
+
*/
|
|
11
|
+
export type RetryCallbackParams = {
|
|
12
|
+
/** This will be `0` for the first execution, then increment with each retry. */
|
|
13
|
+
retryCount: number;
|
|
14
|
+
/** Only true on the last retry. */
|
|
15
|
+
isLastRetry: boolean;
|
|
16
|
+
/** Only true on the first execution, before any retries. */
|
|
17
|
+
isFirstExecution: boolean;
|
|
18
|
+
/** Only true on the first retry. */
|
|
19
|
+
isFirstRetry: boolean;
|
|
20
|
+
};
|
|
4
21
|
/**
|
|
5
22
|
* Calls `callback` until it doesn't throw an error or throws an error when `maxRetries` is reached.
|
|
6
23
|
* Similar to the `waitUntil` guard from '@augment-vir/assert' but doesn't check the callback's
|
|
@@ -24,9 +41,7 @@ import { type IsEqual } from 'type-fest';
|
|
|
24
41
|
*
|
|
25
42
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
26
43
|
*/
|
|
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<{
|
|
44
|
+
export declare function retry<const T, const Duration extends AtLeastOneDuration | undefined = undefined>(maxRetries: number, callback: (params: RetryCallbackParams) => T, options?: PartialWithUndefined<{
|
|
30
45
|
/**
|
|
31
46
|
* Wait this duration between each retry.
|
|
32
47
|
*
|
|
@@ -27,7 +27,12 @@ export function retry(maxRetries, callback, options = {}) {
|
|
|
27
27
|
}
|
|
28
28
|
function internalRetry(currentRetry, maxRetries, callback, options = {}) {
|
|
29
29
|
try {
|
|
30
|
-
const result = callback(
|
|
30
|
+
const result = callback({
|
|
31
|
+
retryCount: currentRetry,
|
|
32
|
+
isFirstExecution: currentRetry === 0,
|
|
33
|
+
isFirstRetry: currentRetry === 1,
|
|
34
|
+
isLastRetry: currentRetry === maxRetries,
|
|
35
|
+
});
|
|
31
36
|
if (result instanceof Promise) {
|
|
32
37
|
return result.catch(async (error) => {
|
|
33
38
|
if (currentRetry >= maxRetries) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@augment-vir/common",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.51.0",
|
|
4
4
|
"description": "A collection of augments, helpers types, functions, and classes for any JavaScript environment.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"augment",
|
|
@@ -40,8 +40,8 @@
|
|
|
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.51.0",
|
|
44
|
+
"@augment-vir/core": "^31.51.0",
|
|
45
45
|
"@date-vir/duration": "^8.0.0",
|
|
46
46
|
"ansi-styles": "^6.2.3",
|
|
47
47
|
"deepcopy-esm": "^2.1.1",
|