https://github.com/lazycuh/retry
Convenient utilities to retry executing some operation until success or failure at most 3 times
https://github.com/lazycuh/retry
retry retrying
Last synced: 2 months ago
JSON representation
Convenient utilities to retry executing some operation until success or failure at most 3 times
- Host: GitHub
- URL: https://github.com/lazycuh/retry
- Owner: lazycuh
- License: mit
- Created: 2023-11-19T23:55:42.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-07-18T07:14:27.000Z (10 months ago)
- Last Synced: 2025-03-05T10:48:27.717Z (3 months ago)
- Topics: retry, retrying
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@lazycuh/retry
- Size: 122 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# retry [](https://app.circleci.com/pipelines/github/lazycuh/retry?branch=main)
Convenient utilities to retry executing some operation until success or failure at most 3 times.
## Table of contents
- [Installation](#installation)
- [Available APIs](#available-apis)
- [`retry` function](#retry-function)
- [`@Retryable` decorator](#retryable-decorator)## Installation
- `npm`
```
npm i -S @lazycuh/retry
```- `pnpm`
```
pnpm i -S @lazycuh/retry
```- `yarn`
```
yarn add @lazycuh/retry
```## Available APIs
### `retry` function
To imperatively retry some operation, wrap your function/method call inside `retry` as followed:
```ts
import { retry } from '@lazycuh/retry';...
const allUsers = await retry(() => fetchAllUsers(), 1000); // Wait 1000ms between retries, default is 3000ms
...
```### `@Retryable` decorator
Alternatively, you can decorate your methods using `@Retryable` decorator to add retrying logic to them, be sure that your `tsconfig.json` file has `experimentalDecorators` setting enabled, for example:
```json
{
"compilerOptions": {
...
"experimentalDecorators": true,
...
},
}
``````ts
import { Retryable } from '@lazycuh/retry';...
class UserService {
@Retryable(2000) // Wait 2000ms between retries, default is 3000ms
fetchUsers() {
...
}
}...
```When `userService.fetchUsers()` is called, any failures will cause it to rerun until either succeeding or failing at most 3 times after the initial failure.