{"id":51119053,"url":"https://github.com/sulthonzh/retryx","last_synced_at":"2026-06-25T00:30:40.050Z","repository":{"id":365000091,"uuid":"1268914600","full_name":"sulthonzh/retryx","owner":"sulthonzh","description":"Zero-dep retry with exponential backoff, jitter strategies, and retry predicates","archived":false,"fork":false,"pushed_at":"2026-06-15T11:34:50.000Z","size":7,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-15T13:15:21.911Z","etag":null,"topics":["abort","backoff","exponential","jitter","retry","timeout","zero-dependency"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sulthonzh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-14T04:49:28.000Z","updated_at":"2026-06-15T11:25:26.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/sulthonzh/retryx","commit_stats":null,"previous_names":["sulthonzh/retryx"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/sulthonzh/retryx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sulthonzh%2Fretryx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sulthonzh%2Fretryx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sulthonzh%2Fretryx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sulthonzh%2Fretryx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sulthonzh","download_url":"https://codeload.github.com/sulthonzh/retryx/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sulthonzh%2Fretryx/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34755061,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-24T02:00:07.484Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abort","backoff","exponential","jitter","retry","timeout","zero-dependency"],"created_at":"2026-06-25T00:30:39.989Z","updated_at":"2026-06-25T00:30:40.044Z","avatar_url":"https://github.com/sulthonzh.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# retryx\n\nZero-dependency retry with exponential backoff, jitter strategies, and retry predicates.\n\nBecause production code fails, and `try/catch` isn't a strategy.\n\n## Why\n\nEvery project eventually needs retries — API calls, DB connections, file locks. Most implementations are copy-pasted Stack Overflow snippets with a `setTimeout` and a prayer. This does it properly:\n\n- **4 jitter strategies** (none, full, equal, decorrelated) to prevent thundering herd\n- **Retry predicates** — only retry on specific errors\n- **Per-attempt timeouts** — kill hangs before they cascade\n- **AbortSignal support** — cancel retries from anywhere\n- **Zero dependencies** — nothing to audit, nothing to break\n\n## Install\n\n```bash\nnpm install retryx\n```\n\n## Quick Start\n\n```js\nimport { retry } from 'retryx';\n\n// Retry a flaky API call\nconst data = await retry(\n  () =\u003e fetch('https://api.example.com/data').then(r =\u003e r.json()),\n  { retries: 5, base: 200 }\n);\n```\n\n## API\n\n### `retry(fn, opts)`\n\nRetry an async function with exponential backoff.\n\n```js\nconst result = await retry(\n  async (attempt) =\u003e {\n    console.log(`Attempt ${attempt}...`);\n    return doWork();\n  },\n  {\n    retries: 3,           // max retries (total attempts = retries + 1)\n    base: 100,            // base delay in ms\n    factor: 2,            // exponential multiplier\n    maxDelay: 30000,      // cap on delay\n    jitter: 'full',       // 'none' | 'full' | 'equal' | 'decorrelated'\n    timeout: 5000,        // per-attempt timeout (0 = disabled)\n    signal: controller.signal,  // AbortSignal\n    onRetry: (err, attempt, delay) =\u003e {\n      console.log(`Attempt ${attempt} failed, retrying in ${delay}ms`);\n    },\n    shouldRetry: (err) =\u003e {\n      // Only retry on network errors, not 4xx\n      return err.code === 'ECONNRESET' || err.code === 'ETIMEDOUT';\n    },\n  }\n);\n```\n\n### `retryable(fn, opts)`\n\nCreate a pre-configured retry wrapper.\n\n```js\nimport { retryable } from 'retryx';\n\nconst fetchRetry = retryable(fetch, { retries: 3, base: 200 });\n\n// Use anywhere — retries are baked in\nconst res = await fetchRetry('https://api.example.com/data');\n```\n\n### `computeDelay(attempt, opts)`\n\nCalculate the delay for a specific attempt. Useful for UIs that show retry countdowns.\n\n```js\nimport { computeDelay } from 'retryx';\n\nconst { delay } = computeDelay(3, { base: 100, factor: 2 });\n// delay = 0-400 (with full jitter)\n```\n\n### `schedule(attempts, opts)`\n\nGenerate the full retry schedule without executing anything.\n\n```js\nimport { schedule } from 'retryx';\n\nconst delays = schedule(5, { base: 100, factor: 2, jitter: 'none' });\n// [100, 200, 400, 800, 1600]\n```\n\n## Jitter Strategies\n\nJitter prevents synchronized retry storms when multiple clients fail simultaneously.\n\n| Strategy | Formula | Spread |\n|----------|---------|--------|\n| `none` | `base * factor^(n-1)` | None — deterministic |\n| `full` | `random(0, computed)` | Widest — best for load distribution |\n| `equal` | `computed/2 + random(0, computed/2)` | Medium — tighter clustering |\n| `decorrelated` | `random(base, prevDelay * 3)` | Adaptive — prevents synchronization |\n\n**Recommendation:** Use `full` (default) for most cases. Use `decorrelated` for systems with many concurrent clients (AWS recommends this).\n\n## Errors\n\n- `RetryExhaustedError` — thrown when all retries are used up. Has `.attempts` and `.lastError`.\n- `RetryAbortError` — thrown when an AbortSignal is triggered.\n\n## CLI\n\n```bash\n# Not applicable — this is a library.\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsulthonzh%2Fretryx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsulthonzh%2Fretryx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsulthonzh%2Fretryx/lists"}