{"id":23789992,"url":"https://github.com/blackglory/extra-retry","last_synced_at":"2026-05-06T19:09:53.833Z","repository":{"id":44955719,"uuid":"350262516","full_name":"BlackGlory/extra-retry","owner":"BlackGlory","description":"🌲 Yet another retry library, but functional style","archived":false,"fork":false,"pushed_at":"2023-06-11T02:42:42.000Z","size":914,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-03T20:07:16.255Z","etag":null,"topics":["browser","esm","library","nodejs","npm-package","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/extra-retry","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/BlackGlory.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-22T08:22:24.000Z","updated_at":"2023-01-27T12:24:07.000Z","dependencies_parsed_at":"2023-02-15T09:40:57.536Z","dependency_job_id":null,"html_url":"https://github.com/BlackGlory/extra-retry","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlackGlory%2Fextra-retry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlackGlory%2Fextra-retry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlackGlory%2Fextra-retry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlackGlory%2Fextra-retry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BlackGlory","download_url":"https://codeload.github.com/BlackGlory/extra-retry/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240018690,"owners_count":19734872,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["browser","esm","library","nodejs","npm-package","typescript"],"created_at":"2025-01-01T17:17:56.102Z","updated_at":"2026-05-06T19:09:53.825Z","avatar_url":"https://github.com/BlackGlory.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# extra-retry\nYet another retry library, but functional style.\n\n## Install\n```sh\nnpm install --save extra-retry\n# or\nyarn add extra-retry\n```\n\n## Usage\n```ts\nimport { retryUntil, anyOf, maxRetries, delay } from 'extra-retry'\nimport ms from 'ms'\n\nawait retryUntil(\n  anyOf(\n    maxRetries(3)\n  , delay(ms('5s'))\n  )\n, fn\n)\n```\n\n## API\n```ts\ninterface IContext {\n  error: unknown\n  retries: number // the number of retries, starting from 0.\n}\n\ntype IPredicate\u003cT = unknown\u003e = (context: IContext) =\u003e Awaitable\u003cT\u003e\n```\n\n### retryUntil\n```ts\nfunction retryUntil(predicate: IPredicate): \u003cT\u003e(fn: () =\u003e Awaitable\u003cT\u003e) =\u003e Promise\u003cT\u003e\nfunction retryUntil\u003cT\u003e(predicate: IPredicate, fn: () =\u003e Awaitable\u003cT\u003e): Promise\u003cT\u003e\n```\n\nIf `fn` throws an error,\nretry until the return value of the `predicate` is [Truthy].\n\n[Truthy]: https://developer.mozilla.org/en-US/docs/Glossary/Truthy\n\n### withRetryUntil\n```ts\nfunction withRetryUntil(\n  predicate: IPredicate\n): \u003cArgs extends unknown[], Result\u003e(\n  fn: (...args: Args) =\u003e Awaitable\u003cResult\u003e\n) =\u003e (...args: Args) =\u003e Promise\u003cResult\u003e\nfunction withRetryUntil\u003cArgs extends unknown[], Result\u003e(\n  predicate: IPredicate\n, fn: (...args: Args) =\u003e Awaitable\u003cResult\u003e\n): (...args: Args) =\u003e Promise\u003cResult\u003e\n```\n\nA simple wrapper around `retryUntil`.\n\n### Helpers\n#### anyOf\n```ts\nfunction anyOf(...predicates: Array\u003cIPredicate | Falsy\u003e): IPredicate\u003cboolean\u003e\n```\n\nEquivalent to\n```ts\ncontext =\u003e (predicate1 \u0026\u0026 await predicate1(context))\n        || (predicate2 \u0026\u0026 await predicate2(context))\n        || ...\n        || (predicateN \u0026\u0026 await predicateN(context))\n```\n\n#### delay\n```ts\nfunction delay(ms: number): IPredicate\n```\n\n#### exponentialBackoff\n```ts\nfunction exponentialBackoff({\n  baseTimeout\n, maxTimeout = Infinity\n, factor = 2\n, jitter = true\n}: {\n  baseTimeout: number\n  maxTimeout?: number\n  factor?: number\n  jitter?: boolean\n}): IPredicate\u003cboolean\u003e\n```\n\nEquivalent to\n```ts\nconst timeout = Math.min(factor ** retries * baseTimeout, maxTimeout)\ndelay(jitter ? randomIntInclusive(0, timeout) : timeout)\n```\n\n#### maxRetries\n```ts\nfunction maxRetries(times: number): IPredicate\u003cboolean\u003e\n```\n\n#### notRetryOn\n```ts\nfunction notRetryOn(errors: Array\u003cConstructor\u003cError\u003e\u003e): IPredicate\u003cboolean\u003e\n```\n\nBlacklist.\n\n#### notRetryOnCommonFatalErrors\n```ts\nconst notRetryOnCommonFatalErrors: IPredicate\u003cboolean\u003e\n```\n\nThis predicate blacklists theses errors:\n- `SyntaxError`\n- `ReferenceError`\n- `RangeError`\n- `URIError`\n\nThere is no `TypeError` because `TypeError` does not mean\n\"a value is not of the expected type\",\nit has been abused for various purposes.\n\n#### retryOn\n```ts\nfunction retryOn(errors: Array\u003cConstructor\u003cError\u003e\u003e): IPredicate\u003cboolean\u003e\n```\n\nWhitelist.\n\n#### signal\n```ts\nfunction signal(abortSignal: AbortSignal): IPredicate\u003cboolean\u003e\n```\n\n#### tap\n```ts\nfunction tap(fn: (context: IContext) =\u003e void): IPredicate\u003cfalse\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblackglory%2Fextra-retry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblackglory%2Fextra-retry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblackglory%2Fextra-retry/lists"}