Skip to content

HK321/retryx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔁 retryx

npm version npm downloads codecov license

A tiny, flexible, Promise-based retry utility with support for delays, exponential backoff, per-attempt timeouts, and custom retry conditions.

🚀 Features

  • Retry any async function
  • Delay and exponential backoff
  • Timeout per attempt
  • Custom retry filters
  • onRetry logging hook
  • Zero dependencies, TypeScript-ready

📦 Installation

npm install retryx
# or
yarn add retryx

💡 Usage

import { retry } from 'retryx'

const result = await retry(() => fetch('https://api.example.com'), {
  maxAttempts: 3,
  delay: 500,
  backoff: true,
  onRetry: (err, attempt) =>
    console.log(`Attempt ${attempt} failed: ${err.message}`),
})

🔧 Options

Option Type Default Description
maxAttempts number 3 Max number of attempts (including the first)
delay number 0 Delay in ms between attempts
backoff boolean false Exponential backoff (delay × 2ⁿ)
timeout number undefined Timeout per attempt in ms
onRetry (error, attempt) => void undefined Callback after each failed attempt
retryOn (error) => boolean Always Custom error filter to allow/disallow retries

❌ Example: Reject after timeout

await retry(
  () => new Promise((res) => setTimeout(() => res('done'), 300)),
  { timeout: 100 }
)
// ➡️ throws: Retry attempt timed out

✅ TypeScript Support

Built in — no extra types needed.


🛡️ License

MIT — build cool things with it!

About

A simple library to make the retry logic customizable and modular

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors