1.0.2 • Published 7 months ago

@harisk/retryx v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

🔁 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

OptionTypeDefaultDescription
maxAttemptsnumber3Max number of attempts (including the first)
delaynumber0Delay in ms between attempts
backoffbooleanfalseExponential backoff (delay × 2ⁿ)
timeoutnumberundefinedTimeout per attempt in ms
onRetry(error, attempt) => voidundefinedCallback after each failed attempt
retryOn(error) => booleanAlwaysCustom 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!

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago