Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/khrj/p-retried
Retry a promise-returning or async function. Abstraction for exponential and custom retry strategies for failed operations
https://github.com/khrj/p-retried
abstraction async deno exponential-backoff function port promise promise-await retry
Last synced: 9 days ago
JSON representation
Retry a promise-returning or async function. Abstraction for exponential and custom retry strategies for failed operations
- Host: GitHub
- URL: https://github.com/khrj/p-retried
- Owner: khrj
- License: mit
- Created: 2021-02-07T16:49:30.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-07-12T11:25:26.000Z (over 3 years ago)
- Last Synced: 2024-10-28T12:15:55.783Z (18 days ago)
- Topics: abstraction, async, deno, exponential-backoff, function, port, promise, promise-await, retry
- Language: TypeScript
- Homepage: https://deno.land/x/p_retried
- Size: 38.1 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Promise Retried
Retry a promise-returning or async function. Deno port of sindresorhus's p-retry for node
Abstraction for exponential and custom retry strategies for failed operations
## Usage
```ts
import pRetried, {
AbortError,
} from "https://deno.land/x/[email protected]/mod.ts"async function run() {
const response = await fetch("https://sindresorhus.com/unicorn")// Abort retrying if the resource doesn't exist
if (response.status === 404) {
throw new AbortError(response.statusText)
}return response.blob()
}console.log(await pRetried(run, { retries: 5 }))
```## API
See https://doc.deno.land/https/deno.land/x/[email protected]/mod.ts
## Tip
You can pass arguments to the function being retried by wrapping it in an inline arrow function:
```js
import pRetried from "https://deno.land/x/[email protected]/mod.ts"const run = async emoji => {
// …
}// Without arguments
await pRetried(run, {
retries: 5,
})// With arguments
await pRetried(() => run("🦄"), {
retries: 5,
})
```## Supporters
- HUGE thanks to @sindresorhus -- this repository is mostly his code, modified to work with Deno
[![Stargazers repo roster for @khrj/p-retried](https://reporoster.com/stars/khrj/p-retried)](https://github.com/khrj/p-retried/stargazers)
[![Forkers repo roster for @khrj/p-retried](https://reporoster.com/forks/khrj/p-retried)](https://github.com/khrj/p-retried/network/members)
## Related
- [p-timeout](https://github.com/khrj/p-timeout)
- [p-queue](https://github.com/khrj/p-queue)
- [retried](https://github.com/khrj/retried)
- [...more](https://github.com/khrj/deno-modules)## License
- Promise Retried is licensed under the MIT license.
- Code is adapted from [Sindre's p-retry for node](https://github.com/sindresorhus/p-retry) (also under the MIT license)