@xylabs/retry 5.0.83 → 5.0.84
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/README.md +26 -0
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/retry.d.ts +12 -0
- package/dist/neutral/retry.d.ts.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -42,6 +42,8 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
42
42
|
function retry<T>(func, config?): Promise<T | undefined>;
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
+
Retries an async function with exponential backoff until it completes or retries are exhausted.
|
|
46
|
+
|
|
45
47
|
## Type Parameters
|
|
46
48
|
|
|
47
49
|
### T
|
|
@@ -54,14 +56,20 @@ function retry<T>(func, config?): Promise<T | undefined>;
|
|
|
54
56
|
|
|
55
57
|
() => `Promisable`\<`T` \| `undefined`\>
|
|
56
58
|
|
|
59
|
+
The function to retry.
|
|
60
|
+
|
|
57
61
|
### config?
|
|
58
62
|
|
|
59
63
|
[`RetryConfigWithComplete`](#../interfaces/RetryConfigWithComplete)\<`T`\>
|
|
60
64
|
|
|
65
|
+
Optional retry configuration including backoff, interval, retries, and completion check.
|
|
66
|
+
|
|
61
67
|
## Returns
|
|
62
68
|
|
|
63
69
|
`Promise`\<`T` \| `undefined`\>
|
|
64
70
|
|
|
71
|
+
The result of the function, or undefined if all retries were exhausted.
|
|
72
|
+
|
|
65
73
|
### interfaces
|
|
66
74
|
|
|
67
75
|
### <a id="RetryConfig"></a>RetryConfig
|
|
@@ -70,6 +78,8 @@ function retry<T>(func, config?): Promise<T | undefined>;
|
|
|
70
78
|
|
|
71
79
|
***
|
|
72
80
|
|
|
81
|
+
Configuration for retry behavior.
|
|
82
|
+
|
|
73
83
|
## Extended by
|
|
74
84
|
|
|
75
85
|
- [`RetryConfigWithComplete`](#RetryConfigWithComplete)
|
|
@@ -82,6 +92,8 @@ function retry<T>(func, config?): Promise<T | undefined>;
|
|
|
82
92
|
optional backoff: number;
|
|
83
93
|
```
|
|
84
94
|
|
|
95
|
+
Multiplier applied to the interval after each retry. Defaults to 2.
|
|
96
|
+
|
|
85
97
|
***
|
|
86
98
|
|
|
87
99
|
### interval?
|
|
@@ -90,6 +102,8 @@ optional backoff: number;
|
|
|
90
102
|
optional interval: number;
|
|
91
103
|
```
|
|
92
104
|
|
|
105
|
+
Initial delay in milliseconds between retries. Defaults to 100.
|
|
106
|
+
|
|
93
107
|
***
|
|
94
108
|
|
|
95
109
|
### retries?
|
|
@@ -98,12 +112,16 @@ optional interval: number;
|
|
|
98
112
|
optional retries: number;
|
|
99
113
|
```
|
|
100
114
|
|
|
115
|
+
Maximum number of retry attempts. Defaults to 0 (no retries).
|
|
116
|
+
|
|
101
117
|
### <a id="RetryConfigWithComplete"></a>RetryConfigWithComplete
|
|
102
118
|
|
|
103
119
|
[**@xylabs/retry**](#../README)
|
|
104
120
|
|
|
105
121
|
***
|
|
106
122
|
|
|
123
|
+
Retry configuration extended with a custom completion check.
|
|
124
|
+
|
|
107
125
|
## Extends
|
|
108
126
|
|
|
109
127
|
- [`RetryConfig`](#RetryConfig)
|
|
@@ -122,6 +140,8 @@ optional retries: number;
|
|
|
122
140
|
optional backoff: number;
|
|
123
141
|
```
|
|
124
142
|
|
|
143
|
+
Multiplier applied to the interval after each retry. Defaults to 2.
|
|
144
|
+
|
|
125
145
|
### Inherited from
|
|
126
146
|
|
|
127
147
|
[`RetryConfig`](#RetryConfig).[`backoff`](RetryConfig.md#backoff)
|
|
@@ -134,6 +154,8 @@ optional backoff: number;
|
|
|
134
154
|
optional interval: number;
|
|
135
155
|
```
|
|
136
156
|
|
|
157
|
+
Initial delay in milliseconds between retries. Defaults to 100.
|
|
158
|
+
|
|
137
159
|
### Inherited from
|
|
138
160
|
|
|
139
161
|
[`RetryConfig`](#RetryConfig).[`interval`](RetryConfig.md#interval)
|
|
@@ -146,6 +168,8 @@ optional interval: number;
|
|
|
146
168
|
optional retries: number;
|
|
147
169
|
```
|
|
148
170
|
|
|
171
|
+
Maximum number of retry attempts. Defaults to 0 (no retries).
|
|
172
|
+
|
|
149
173
|
### Inherited from
|
|
150
174
|
|
|
151
175
|
[`RetryConfig`](#RetryConfig).[`retries`](RetryConfig.md#retries)
|
|
@@ -158,6 +182,8 @@ optional retries: number;
|
|
|
158
182
|
optional complete: (result?) => boolean;
|
|
159
183
|
```
|
|
160
184
|
|
|
185
|
+
Determines whether the result is considered complete. Defaults to checking for a defined value.
|
|
186
|
+
|
|
161
187
|
### Parameters
|
|
162
188
|
|
|
163
189
|
#### result?
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/retry.ts"],"sourcesContent":["import { delay } from '@xylabs/delay'\nimport type { Promisable } from '@xylabs/promise'\n\nexport interface RetryConfig {\n backoff?: number\n interval?: number\n retries?: number\n}\n\nexport interface RetryConfigWithComplete<T = unknown> extends RetryConfig {\n complete?: (result?: T) => boolean\n}\n\nexport const retry = async <T = unknown>(func: () => Promisable<T | undefined>, config?: RetryConfigWithComplete<T>): Promise<T | undefined> => {\n const {\n complete = (value: T | undefined) => value !== undefined, retries = 0, interval = 100, backoff = 2,\n } = config ?? {}\n const result = await func()\n if (complete(result)) {\n return result\n }\n if (retries <= 0) {\n return undefined\n }\n await delay(interval)\n return retry(func, {\n backoff, complete, interval: interval * backoff, retries: retries - 1,\n })\n}\n"],"mappings":";AAAA,SAAS,aAAa;
|
|
1
|
+
{"version":3,"sources":["../../src/retry.ts"],"sourcesContent":["import { delay } from '@xylabs/delay'\nimport type { Promisable } from '@xylabs/promise'\n\n/** Configuration for retry behavior. */\nexport interface RetryConfig {\n /** Multiplier applied to the interval after each retry. Defaults to 2. */\n backoff?: number\n /** Initial delay in milliseconds between retries. Defaults to 100. */\n interval?: number\n /** Maximum number of retry attempts. Defaults to 0 (no retries). */\n retries?: number\n}\n\n/** Retry configuration extended with a custom completion check. */\nexport interface RetryConfigWithComplete<T = unknown> extends RetryConfig {\n /** Determines whether the result is considered complete. Defaults to checking for a defined value. */\n complete?: (result?: T) => boolean\n}\n\n/**\n * Retries an async function with exponential backoff until it completes or retries are exhausted.\n * @param func - The function to retry.\n * @param config - Optional retry configuration including backoff, interval, retries, and completion check.\n * @returns The result of the function, or undefined if all retries were exhausted.\n */\nexport const retry = async <T = unknown>(func: () => Promisable<T | undefined>, config?: RetryConfigWithComplete<T>): Promise<T | undefined> => {\n const {\n complete = (value: T | undefined) => value !== undefined, retries = 0, interval = 100, backoff = 2,\n } = config ?? {}\n const result = await func()\n if (complete(result)) {\n return result\n }\n if (retries <= 0) {\n return undefined\n }\n await delay(interval)\n return retry(func, {\n backoff, complete, interval: interval * backoff, retries: retries - 1,\n })\n}\n"],"mappings":";AAAA,SAAS,aAAa;AAyBf,IAAM,QAAQ,OAAoB,MAAuC,WAAgE;AAC9I,QAAM;AAAA,IACJ,WAAW,CAAC,UAAyB,UAAU;AAAA,IAAW,UAAU;AAAA,IAAG,WAAW;AAAA,IAAK,UAAU;AAAA,EACnG,IAAI,UAAU,CAAC;AACf,QAAM,SAAS,MAAM,KAAK;AAC1B,MAAI,SAAS,MAAM,GAAG;AACpB,WAAO;AAAA,EACT;AACA,MAAI,WAAW,GAAG;AAChB,WAAO;AAAA,EACT;AACA,QAAM,MAAM,QAAQ;AACpB,SAAO,MAAM,MAAM;AAAA,IACjB;AAAA,IAAS;AAAA,IAAU,UAAU,WAAW;AAAA,IAAS,SAAS,UAAU;AAAA,EACtE,CAAC;AACH;","names":[]}
|
package/dist/neutral/retry.d.ts
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import type { Promisable } from '@xylabs/promise';
|
|
2
|
+
/** Configuration for retry behavior. */
|
|
2
3
|
export interface RetryConfig {
|
|
4
|
+
/** Multiplier applied to the interval after each retry. Defaults to 2. */
|
|
3
5
|
backoff?: number;
|
|
6
|
+
/** Initial delay in milliseconds between retries. Defaults to 100. */
|
|
4
7
|
interval?: number;
|
|
8
|
+
/** Maximum number of retry attempts. Defaults to 0 (no retries). */
|
|
5
9
|
retries?: number;
|
|
6
10
|
}
|
|
11
|
+
/** Retry configuration extended with a custom completion check. */
|
|
7
12
|
export interface RetryConfigWithComplete<T = unknown> extends RetryConfig {
|
|
13
|
+
/** Determines whether the result is considered complete. Defaults to checking for a defined value. */
|
|
8
14
|
complete?: (result?: T) => boolean;
|
|
9
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Retries an async function with exponential backoff until it completes or retries are exhausted.
|
|
18
|
+
* @param func - The function to retry.
|
|
19
|
+
* @param config - Optional retry configuration including backoff, interval, retries, and completion check.
|
|
20
|
+
* @returns The result of the function, or undefined if all retries were exhausted.
|
|
21
|
+
*/
|
|
10
22
|
export declare const retry: <T = unknown>(func: () => Promisable<T | undefined>, config?: RetryConfigWithComplete<T>) => Promise<T | undefined>;
|
|
11
23
|
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/retry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,uBAAuB,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,WAAW;IACvE,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,OAAO,CAAA;CACnC;AAED,eAAO,MAAM,KAAK,GAAU,CAAC,GAAG,OAAO,EAAE,MAAM,MAAM,UAAU,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,SAAS,uBAAuB,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAe1I,CAAA"}
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/retry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,wCAAwC;AACxC,MAAM,WAAW,WAAW;IAC1B,0EAA0E;IAC1E,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,sEAAsE;IACtE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,mEAAmE;AACnE,MAAM,WAAW,uBAAuB,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,WAAW;IACvE,sGAAsG;IACtG,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,OAAO,CAAA;CACnC;AAED;;;;;GAKG;AACH,eAAO,MAAM,KAAK,GAAU,CAAC,GAAG,OAAO,EAAE,MAAM,MAAM,UAAU,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,SAAS,uBAAuB,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAe1I,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/retry",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.84",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"delay",
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"!**/*.test.*"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@xylabs/delay": "~5.0.
|
|
46
|
-
"@xylabs/promise": "~5.0.
|
|
45
|
+
"@xylabs/delay": "~5.0.84",
|
|
46
|
+
"@xylabs/promise": "~5.0.84"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@xylabs/ts-scripts-yarn3": "~7.4.
|
|
50
|
-
"@xylabs/tsconfig": "~7.4.
|
|
49
|
+
"@xylabs/ts-scripts-yarn3": "~7.4.13",
|
|
50
|
+
"@xylabs/tsconfig": "~7.4.13",
|
|
51
51
|
"typescript": "~5.9.3",
|
|
52
52
|
"vitest": "^4.0.18"
|
|
53
53
|
},
|