@xylabs/retry 5.0.83 → 5.0.86
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 +39 -89
- 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
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
|
|
16
16
|
Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
17
17
|
|
|
18
|
+
|
|
19
|
+
|
|
18
20
|
## Reference
|
|
19
21
|
|
|
20
22
|
**@xylabs/retry**
|
|
@@ -23,12 +25,16 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
23
25
|
|
|
24
26
|
## Interfaces
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
| Interface | Description |
|
|
29
|
+
| ------ | ------ |
|
|
30
|
+
| [RetryConfig](#interfaces/RetryConfig) | Configuration for retry behavior. |
|
|
31
|
+
| [RetryConfigWithComplete](#interfaces/RetryConfigWithComplete) | Retry configuration extended with a custom completion check. |
|
|
28
32
|
|
|
29
33
|
## Functions
|
|
30
34
|
|
|
31
|
-
|
|
35
|
+
| Function | Description |
|
|
36
|
+
| ------ | ------ |
|
|
37
|
+
| [retry](#functions/retry) | Retries an async function with exponential backoff until it completes or retries are exhausted. |
|
|
32
38
|
|
|
33
39
|
### functions
|
|
34
40
|
|
|
@@ -39,29 +45,30 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
39
45
|
***
|
|
40
46
|
|
|
41
47
|
```ts
|
|
42
|
-
function retry<T>(func
|
|
48
|
+
function retry<T>(func: () => Promisable<T | undefined>, config?: RetryConfigWithComplete<T>): Promise<T | undefined>;
|
|
43
49
|
```
|
|
44
50
|
|
|
45
|
-
|
|
51
|
+
Retries an async function with exponential backoff until it completes or retries are exhausted.
|
|
46
52
|
|
|
47
|
-
|
|
53
|
+
## Type Parameters
|
|
48
54
|
|
|
49
|
-
|
|
55
|
+
| Type Parameter | Default type |
|
|
56
|
+
| ------ | ------ |
|
|
57
|
+
| `T` | `unknown` |
|
|
50
58
|
|
|
51
59
|
## Parameters
|
|
52
60
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
() => `Promisable`\<`T` \| `undefined`\>
|
|
56
|
-
|
|
57
|
-
### config?
|
|
58
|
-
|
|
59
|
-
[`RetryConfigWithComplete`](#../interfaces/RetryConfigWithComplete)\<`T`\>
|
|
61
|
+
| Parameter | Type | Description |
|
|
62
|
+
| ------ | ------ | ------ |
|
|
63
|
+
| `func` | () => `Promisable`\<`T` \| `undefined`\> | The function to retry. |
|
|
64
|
+
| `config?` | [`RetryConfigWithComplete`](#../interfaces/RetryConfigWithComplete)\<`T`\> | Optional retry configuration including backoff, interval, retries, and completion check. |
|
|
60
65
|
|
|
61
66
|
## Returns
|
|
62
67
|
|
|
63
68
|
`Promise`\<`T` \| `undefined`\>
|
|
64
69
|
|
|
70
|
+
The result of the function, or undefined if all retries were exhausted.
|
|
71
|
+
|
|
65
72
|
### interfaces
|
|
66
73
|
|
|
67
74
|
### <a id="RetryConfig"></a>RetryConfig
|
|
@@ -70,33 +77,19 @@ function retry<T>(func, config?): Promise<T | undefined>;
|
|
|
70
77
|
|
|
71
78
|
***
|
|
72
79
|
|
|
80
|
+
Configuration for retry behavior.
|
|
81
|
+
|
|
73
82
|
## Extended by
|
|
74
83
|
|
|
75
84
|
- [`RetryConfigWithComplete`](#RetryConfigWithComplete)
|
|
76
85
|
|
|
77
86
|
## Properties
|
|
78
87
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
***
|
|
86
|
-
|
|
87
|
-
### interval?
|
|
88
|
-
|
|
89
|
-
```ts
|
|
90
|
-
optional interval: number;
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
***
|
|
94
|
-
|
|
95
|
-
### retries?
|
|
96
|
-
|
|
97
|
-
```ts
|
|
98
|
-
optional retries: number;
|
|
99
|
-
```
|
|
88
|
+
| Property | Type | Description |
|
|
89
|
+
| ------ | ------ | ------ |
|
|
90
|
+
| <a id="backoff"></a> `backoff?` | `number` | Multiplier applied to the interval after each retry. Defaults to 2. |
|
|
91
|
+
| <a id="interval"></a> `interval?` | `number` | Initial delay in milliseconds between retries. Defaults to 100. |
|
|
92
|
+
| <a id="retries"></a> `retries?` | `number` | Maximum number of retry attempts. Defaults to 0 (no retries). |
|
|
100
93
|
|
|
101
94
|
### <a id="RetryConfigWithComplete"></a>RetryConfigWithComplete
|
|
102
95
|
|
|
@@ -104,69 +97,26 @@ optional retries: number;
|
|
|
104
97
|
|
|
105
98
|
***
|
|
106
99
|
|
|
100
|
+
Retry configuration extended with a custom completion check.
|
|
101
|
+
|
|
107
102
|
## Extends
|
|
108
103
|
|
|
109
104
|
- [`RetryConfig`](#RetryConfig)
|
|
110
105
|
|
|
111
106
|
## Type Parameters
|
|
112
107
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
`T`
|
|
108
|
+
| Type Parameter | Default type |
|
|
109
|
+
| ------ | ------ |
|
|
110
|
+
| `T` | `unknown` |
|
|
116
111
|
|
|
117
112
|
## Properties
|
|
118
113
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
### Inherited from
|
|
126
|
-
|
|
127
|
-
[`RetryConfig`](#RetryConfig).[`backoff`](RetryConfig.md#backoff)
|
|
128
|
-
|
|
129
|
-
***
|
|
130
|
-
|
|
131
|
-
### interval?
|
|
132
|
-
|
|
133
|
-
```ts
|
|
134
|
-
optional interval: number;
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
### Inherited from
|
|
138
|
-
|
|
139
|
-
[`RetryConfig`](#RetryConfig).[`interval`](RetryConfig.md#interval)
|
|
140
|
-
|
|
141
|
-
***
|
|
142
|
-
|
|
143
|
-
### retries?
|
|
144
|
-
|
|
145
|
-
```ts
|
|
146
|
-
optional retries: number;
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
### Inherited from
|
|
150
|
-
|
|
151
|
-
[`RetryConfig`](#RetryConfig).[`retries`](RetryConfig.md#retries)
|
|
152
|
-
|
|
153
|
-
***
|
|
154
|
-
|
|
155
|
-
### complete()?
|
|
156
|
-
|
|
157
|
-
```ts
|
|
158
|
-
optional complete: (result?) => boolean;
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
### Parameters
|
|
162
|
-
|
|
163
|
-
#### result?
|
|
164
|
-
|
|
165
|
-
`T`
|
|
166
|
-
|
|
167
|
-
### Returns
|
|
168
|
-
|
|
169
|
-
`boolean`
|
|
114
|
+
| Property | Type | Description | Inherited from |
|
|
115
|
+
| ------ | ------ | ------ | ------ |
|
|
116
|
+
| <a id="backoff"></a> `backoff?` | `number` | Multiplier applied to the interval after each retry. Defaults to 2. | [`RetryConfig`](#RetryConfig).[`backoff`](RetryConfig.md#backoff) |
|
|
117
|
+
| <a id="interval"></a> `interval?` | `number` | Initial delay in milliseconds between retries. Defaults to 100. | [`RetryConfig`](#RetryConfig).[`interval`](RetryConfig.md#interval) |
|
|
118
|
+
| <a id="retries"></a> `retries?` | `number` | Maximum number of retry attempts. Defaults to 0 (no retries). | [`RetryConfig`](#RetryConfig).[`retries`](RetryConfig.md#retries) |
|
|
119
|
+
| <a id="complete"></a> `complete?` | (`result?`: `T`) => `boolean` | Determines whether the result is considered complete. Defaults to checking for a defined value. | - |
|
|
170
120
|
|
|
171
121
|
|
|
172
122
|
Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
|
|
@@ -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.86",
|
|
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.86",
|
|
46
|
+
"@xylabs/promise": "~5.0.86"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@xylabs/ts-scripts-yarn3": "~7.4.
|
|
50
|
-
"@xylabs/tsconfig": "~7.4.
|
|
49
|
+
"@xylabs/ts-scripts-yarn3": "~7.4.16",
|
|
50
|
+
"@xylabs/tsconfig": "~7.4.16",
|
|
51
51
|
"typescript": "~5.9.3",
|
|
52
52
|
"vitest": "^4.0.18"
|
|
53
53
|
},
|