@vyriy/retry 0.1.9
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/LICENSE +21 -0
- package/README.md +46 -0
- package/index.d.ts +2 -0
- package/index.js +1 -0
- package/package.json +40 -0
- package/retry.d.ts +2 -0
- package/retry.js +22 -0
- package/types.d.ts +7 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vyriy contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# @vyriy/retry
|
|
2
|
+
|
|
3
|
+
Retry utility for Vyriy projects.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
This package provides a small wrapper for retrying an async handler a fixed number of times with an optional delay between attempts.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
With npm:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @vyriy/retry
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
With Yarn:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
yarn add @vyriy/retry
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { retry } from '@vyriy/retry';
|
|
27
|
+
|
|
28
|
+
const result = await retry(async () => fetch('https://example.com/data').then((response) => response.json()), {
|
|
29
|
+
retries: 3,
|
|
30
|
+
delay: 250,
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Exports
|
|
35
|
+
|
|
36
|
+
The package exposes both the root entry and the direct utility module:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { retry } from '@vyriy/retry';
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## API
|
|
43
|
+
|
|
44
|
+
- `retry(handler, options?)` retries `handler` until it succeeds or retries are exhausted.
|
|
45
|
+
- `options.retries` controls how many retries happen after the first failure.
|
|
46
|
+
- `options.delay` sets the delay between retries in milliseconds.
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './retry.js';
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vyriy/retry",
|
|
3
|
+
"version": "0.1.9",
|
|
4
|
+
"description": "Retry utility for Vyriy projects",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./index.js",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@vyriy/logger": "0.1.9",
|
|
9
|
+
"@vyriy/pause": "0.1.9"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"types": "./index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./index.d.ts",
|
|
16
|
+
"import": "./index.js",
|
|
17
|
+
"default": "./index.js"
|
|
18
|
+
},
|
|
19
|
+
"./index": {
|
|
20
|
+
"types": "./index.d.ts",
|
|
21
|
+
"import": "./index.js",
|
|
22
|
+
"default": "./index.js"
|
|
23
|
+
},
|
|
24
|
+
"./index.js": {
|
|
25
|
+
"types": "./index.d.ts",
|
|
26
|
+
"import": "./index.js",
|
|
27
|
+
"default": "./index.js"
|
|
28
|
+
},
|
|
29
|
+
"./retry": {
|
|
30
|
+
"types": "./retry.d.ts",
|
|
31
|
+
"import": "./retry.js",
|
|
32
|
+
"default": "./retry.js"
|
|
33
|
+
},
|
|
34
|
+
"./retry.js": {
|
|
35
|
+
"types": "./retry.d.ts",
|
|
36
|
+
"import": "./retry.js",
|
|
37
|
+
"default": "./retry.js"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
package/retry.d.ts
ADDED
package/retry.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { pause } from '@vyriy/pause';
|
|
2
|
+
import { createLogger } from '@vyriy/logger';
|
|
3
|
+
export const retry = async (handler, options = {}) => {
|
|
4
|
+
const logger = createLogger();
|
|
5
|
+
logger.info('Retry options:', options);
|
|
6
|
+
const { retries = 2, delay = 0 } = options;
|
|
7
|
+
const run = async (attempt = retries) => {
|
|
8
|
+
logger.info('Attempt:', attempt);
|
|
9
|
+
try {
|
|
10
|
+
return await handler();
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
logger.info('Retry Error:', error.message);
|
|
14
|
+
if (attempt) {
|
|
15
|
+
await pause(delay);
|
|
16
|
+
return run(attempt - 1);
|
|
17
|
+
}
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
return run();
|
|
22
|
+
};
|
package/types.d.ts
ADDED