@xylabs/retry 5.0.80 → 5.0.82
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 +3 -3
- package/package.json +7 -9
- package/src/index.ts +0 -1
- package/src/retry.ts +0 -29
package/README.md
CHANGED
|
@@ -39,7 +39,7 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
39
39
|
***
|
|
40
40
|
|
|
41
41
|
```ts
|
|
42
|
-
function retry<T>(func, config?): Promise<
|
|
42
|
+
function retry<T>(func, config?): Promise<T | undefined>;
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
## Type Parameters
|
|
@@ -52,7 +52,7 @@ function retry<T>(func, config?): Promise<undefined | T>;
|
|
|
52
52
|
|
|
53
53
|
### func
|
|
54
54
|
|
|
55
|
-
() => `Promisable`\<`
|
|
55
|
+
() => `Promisable`\<`T` \| `undefined`\>
|
|
56
56
|
|
|
57
57
|
### config?
|
|
58
58
|
|
|
@@ -60,7 +60,7 @@ function retry<T>(func, config?): Promise<undefined | T>;
|
|
|
60
60
|
|
|
61
61
|
## Returns
|
|
62
62
|
|
|
63
|
-
`Promise`\<`
|
|
63
|
+
`Promise`\<`T` \| `undefined`\>
|
|
64
64
|
|
|
65
65
|
### interfaces
|
|
66
66
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/retry",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.82",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"delay",
|
|
@@ -29,29 +29,27 @@
|
|
|
29
29
|
"exports": {
|
|
30
30
|
".": {
|
|
31
31
|
"types": "./dist/neutral/index.d.ts",
|
|
32
|
-
"source": "./src/index.ts",
|
|
33
32
|
"default": "./dist/neutral/index.mjs"
|
|
34
33
|
},
|
|
35
34
|
"./package.json": "./package.json"
|
|
36
35
|
},
|
|
37
36
|
"module": "./dist/neutral/index.mjs",
|
|
38
|
-
"source": "./src/index.ts",
|
|
39
37
|
"types": "./dist/neutral/index.d.ts",
|
|
40
38
|
"files": [
|
|
41
39
|
"dist",
|
|
42
|
-
"src",
|
|
43
40
|
"!**/*.bench.*",
|
|
44
41
|
"!**/*.spec.*",
|
|
45
42
|
"!**/*.test.*"
|
|
46
43
|
],
|
|
47
44
|
"dependencies": {
|
|
48
|
-
"@xylabs/delay": "~5.0.
|
|
49
|
-
"@xylabs/promise": "~5.0.
|
|
45
|
+
"@xylabs/delay": "~5.0.82",
|
|
46
|
+
"@xylabs/promise": "~5.0.82"
|
|
50
47
|
},
|
|
51
48
|
"devDependencies": {
|
|
52
|
-
"@xylabs/ts-scripts-yarn3": "~7.
|
|
53
|
-
"@xylabs/tsconfig": "~7.
|
|
54
|
-
"typescript": "~5.9.3"
|
|
49
|
+
"@xylabs/ts-scripts-yarn3": "~7.4.11",
|
|
50
|
+
"@xylabs/tsconfig": "~7.4.11",
|
|
51
|
+
"typescript": "~5.9.3",
|
|
52
|
+
"vitest": "^4.0.18"
|
|
55
53
|
},
|
|
56
54
|
"engines": {
|
|
57
55
|
"node": ">=18"
|
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './retry.ts'
|
package/src/retry.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { delay } from '@xylabs/delay'
|
|
2
|
-
import type { Promisable } from '@xylabs/promise'
|
|
3
|
-
|
|
4
|
-
export interface RetryConfig {
|
|
5
|
-
backoff?: number
|
|
6
|
-
interval?: number
|
|
7
|
-
retries?: number
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface RetryConfigWithComplete<T = unknown> extends RetryConfig {
|
|
11
|
-
complete?: (result?: T) => boolean
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const retry = async <T = unknown>(func: () => Promisable<T | undefined>, config?: RetryConfigWithComplete<T>): Promise<T | undefined> => {
|
|
15
|
-
const {
|
|
16
|
-
complete = (value: T | undefined) => value !== undefined, retries = 0, interval = 100, backoff = 2,
|
|
17
|
-
} = config ?? {}
|
|
18
|
-
const result = await func()
|
|
19
|
-
if (complete(result)) {
|
|
20
|
-
return result
|
|
21
|
-
}
|
|
22
|
-
if (retries <= 0) {
|
|
23
|
-
return undefined
|
|
24
|
-
}
|
|
25
|
-
await delay(interval)
|
|
26
|
-
return retry(func, {
|
|
27
|
-
backoff, complete, interval: interval * backoff, retries: retries - 1,
|
|
28
|
-
})
|
|
29
|
-
}
|