{"id":47605263,"url":"https://github.com/ofershap/tiny-retry","last_synced_at":"2026-04-01T19:09:51.447Z","repository":{"id":342388040,"uuid":"1173810799","full_name":"ofershap/tiny-retry","owner":"ofershap","description":"Retry async functions with exponential backoff. Drop-in p-retry replacement. ESM + CJS, zero deps, TypeScript.","archived":false,"fork":false,"pushed_at":"2026-03-19T00:45:49.000Z","size":893,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-19T14:16:58.551Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ofershap.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","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},"funding":{"github":"ofershap"}},"created_at":"2026-03-05T19:21:49.000Z","updated_at":"2026-03-19T00:45:44.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/ofershap/tiny-retry","commit_stats":null,"previous_names":["ofershap/tiny-retry"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ofershap/tiny-retry","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ofershap%2Ftiny-retry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ofershap%2Ftiny-retry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ofershap%2Ftiny-retry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ofershap%2Ftiny-retry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ofershap","download_url":"https://codeload.github.com/ofershap/tiny-retry/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ofershap%2Ftiny-retry/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31291090,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-01T13:12:26.723Z","status":"ssl_error","status_checked_at":"2026-04-01T13:12:25.102Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2026-04-01T19:09:50.708Z","updated_at":"2026-04-01T19:09:51.434Z","avatar_url":"https://github.com/ofershap.png","language":"TypeScript","funding_links":["https://github.com/sponsors/ofershap"],"categories":[],"sub_categories":[],"readme":"# tiny-retry\n\n[![npm version](https://img.shields.io/npm/v/tiny-pretry.svg)](https://www.npmjs.com/package/tiny-pretry)\n[![npm downloads](https://img.shields.io/npm/dm/tiny-pretry.svg)](https://www.npmjs.com/package/tiny-pretry)\n[![CI](https://github.com/ofershap/tiny-retry/actions/workflows/ci.yml/badge.svg)](https://github.com/ofershap/tiny-retry/actions/workflows/ci.yml)\n[![TypeScript](https://img.shields.io/badge/TypeScript-strict-blue.svg)](https://www.typescriptlang.org/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nRetry async functions with exponential backoff. Same API as [`p-retry`](https://github.com/sindresorhus/p-retry), but ships both ESM and CJS with zero dependencies.\n\n```ts\nimport { pRetry } from \"tiny-pretry\";\n\nconst data = await pRetry(\n  () =\u003e fetch(\"https://api.example.com/data\").then((r) =\u003e r.json()),\n  { retries: 3 },\n);\n```\n\n\u003e ~800 bytes gzipped. Zero dependencies. Replaces p-retry without the ESM-only headache.\n\n![Demo](assets/demo.gif)\n\n\u003csub\u003eDemo built with \u003ca href=\"https://github.com/ofershap/remotion-readme-kit\"\u003eremotion-readme-kit\u003c/a\u003e\u003c/sub\u003e\n\n## Install\n\n```bash\nnpm install tiny-pretry\n```\n\n## Usage\n\n```ts\nimport { pRetry } from \"tiny-pretry\";\n\nconst result = await pRetry(\n  async (attemptNumber) =\u003e {\n    console.log(`Attempt ${attemptNumber}`);\n    const res = await fetch(\"https://api.example.com\");\n    if (!res.ok) throw new Error(res.statusText);\n    return res.json();\n  },\n  { retries: 5 },\n);\n```\n\n### Stop retrying early\n\n```ts\nimport { pRetry, AbortError } from \"tiny-pretry\";\n\nawait pRetry(\n  async () =\u003e {\n    const res = await fetch(\"https://api.example.com\");\n    if (res.status === 401) {\n      throw new AbortError(\"Not authorized, retrying won't help\");\n    }\n    return res.json();\n  },\n  { retries: 5 },\n);\n```\n\n### Track failed attempts\n\n```ts\nawait pRetry(doWork, {\n  retries: 5,\n  onFailedAttempt: (error) =\u003e {\n    console.log(\n      `Attempt ${error.attemptNumber} failed. ${error.retriesLeft} retries left.`,\n    );\n  },\n});\n```\n\n### Cancel with AbortSignal\n\n```ts\nconst controller = new AbortController();\nsetTimeout(() =\u003e controller.abort(), 10000);\n\nawait pRetry(unreliableCall, {\n  retries: 10,\n  signal: controller.signal,\n});\n```\n\n## Differences from `p-retry`\n\n`p-retry` v6+ is ESM-only. If you `require(\"p-retry\")` in a CommonJS project, you get `ERR_REQUIRE_ESM`. `tiny-retry` works with both `import` and `require()`.\n\n|              | `p-retry`                   | `tiny-retry` |\n| ------------ | --------------------------- | ------------ |\n| CJS support  | v5 only (v6+ ESM-only)      | ESM + CJS    |\n| Dependencies | `retry`, `is-network-error` | 0            |\n| TypeScript   | separate @types             | native       |\n| Export       | default                     | named        |\n\n## Migrating from p-retry\n\n```diff\n- import pRetry from \"p-retry\";\n+ import { pRetry } from \"tiny-pretry\";\n```\n\nOne line. Everything else stays the same.\n\n## API\n\n### `pRetry(fn, options?)`\n\nRetries `fn` until it succeeds or retries are exhausted.\n\n- `fn(attemptNumber)` - function to retry (attempt starts at 1)\n- `options.retries` - max retries (default: `10`)\n- `options.factor` - exponential factor (default: `2`)\n- `options.minTimeout` - initial delay in ms (default: `1000`)\n- `options.maxTimeout` - max delay cap in ms (default: `Infinity`)\n- `options.randomize` - add jitter to delays (default: `false`)\n- `options.signal` - `AbortSignal` for cancellation\n- `options.onFailedAttempt(error)` - called after each failure\n\n### `AbortError`\n\nThrow `new AbortError(message)` or `new AbortError(error)` inside `fn` to stop retrying immediately.\n\n### `FailedAttemptError`\n\nThe error passed to `onFailedAttempt` has two extra properties:\n\n- `attemptNumber` - which attempt just failed (1-based)\n- `retriesLeft` - how many retries remain\n\n## The tiny-\\* family\n\nDrop-in replacements for sindresorhus async utilities. All ship ESM + CJS with zero dependencies.\n\n| Package                                                | Replaces             | What it does                   |\n| ------------------------------------------------------ | -------------------- | ------------------------------ |\n| [tiny-limit](https://github.com/ofershap/tiny-limit)   | p-limit              | Concurrency limiter            |\n| [tiny-map](https://github.com/ofershap/tiny-map)       | p-map                | Concurrent map with order      |\n| **tiny-retry**                                         | p-retry              | Retry with exponential backoff |\n| [tiny-queue](https://github.com/ofershap/tiny-queue)   | p-queue              | Priority task queue            |\n| [tiny-ms](https://github.com/ofershap/tiny-ms)         | ms                   | Parse/format durations         |\n| [tiny-escape](https://github.com/ofershap/tiny-escape) | escape-string-regexp | Escape regex chars             |\n\nWant all async utilities in one import? Use [`tiny-pasync`](https://github.com/ofershap/tiny-async).\n\n## Author\n\n[![Made by ofershap](https://gitshow.dev/api/card/ofershap)](https://gitshow.dev/ofershap)\n\n[![LinkedIn](https://img.shields.io/badge/LinkedIn-Connect-0A66C2?style=flat\u0026logo=linkedin\u0026logoColor=white)](https://linkedin.com/in/ofershap)\n[![GitHub](https://img.shields.io/badge/GitHub-Follow-181717?style=flat\u0026logo=github\u0026logoColor=white)](https://github.com/ofershap)\n\n---\n\nIf this saved you from `ERR_REQUIRE_ESM`, [star the repo](https://github.com/ofershap/tiny-retry) or [open an issue](https://github.com/ofershap/tiny-retry/issues) if something breaks.\n\n---\n\n\u003csub\u003eREADME built with [README Builder](https://ofershap.github.io/readme-builder/)\u003c/sub\u003e\n\n## License\n\n[MIT](LICENSE) \u0026copy; [Ofer Shapira](https://github.com/ofershap)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fofershap%2Ftiny-retry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fofershap%2Ftiny-retry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fofershap%2Ftiny-retry/lists"}