{"id":18331285,"url":"https://github.com/coveooss/exponential-backoff","last_synced_at":"2025-05-13T23:10:37.234Z","repository":{"id":38813821,"uuid":"139891453","full_name":"coveooss/exponential-backoff","owner":"coveooss","description":"A utility that allows retrying a function with an exponential delay between attempts.","archived":false,"fork":false,"pushed_at":"2025-04-04T20:16:49.000Z","size":289,"stargazers_count":376,"open_issues_count":6,"forks_count":26,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-05-03T07:56:22.595Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coveooss.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2018-07-05T19:22:09.000Z","updated_at":"2025-04-29T16:29:43.000Z","dependencies_parsed_at":"2024-09-16T21:07:54.150Z","dependency_job_id":"40fd94a7-f955-4b40-a992-371e58b3def2","html_url":"https://github.com/coveooss/exponential-backoff","commit_stats":{"total_commits":89,"total_committers":6,"mean_commits":"14.833333333333334","dds":0.3258426966292135,"last_synced_commit":"f8ae3ed87d4ff94122ea49b9d18f32a8de889670"},"previous_names":["coveo/exponential-backoff"],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coveooss%2Fexponential-backoff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coveooss%2Fexponential-backoff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coveooss%2Fexponential-backoff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coveooss%2Fexponential-backoff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coveooss","download_url":"https://codeload.github.com/coveooss/exponential-backoff/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254042327,"owners_count":22004901,"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":[],"created_at":"2024-11-05T19:29:29.339Z","updated_at":"2025-05-13T23:10:32.201Z","avatar_url":"https://github.com/coveooss.png","language":"TypeScript","funding_links":[],"categories":["Packages"],"sub_categories":[],"readme":"# exponential-backoff\n\nA utility that allows retrying a function with an exponential delay between attempts.\n\n## Installation\n\n```\nnpm i exponential-backoff\n```\n\n## Usage\n\nThe `backOff\u003cT\u003e` function takes a promise-returning function to retry, and an optional `BackOffOptions` object. It returns a `Promise\u003cT\u003e`.\n\n```ts\nfunction backOff\u003cT\u003e(\n  request: () =\u003e Promise\u003cT\u003e,\n  options?: BackOffOptions\n): Promise\u003cT\u003e;\n```\n\nHere is an example retrying a function that calls a hypothetical weather endpoint:\n\n```js\nimport { backOff } from \"exponential-backoff\";\n\nfunction getWeather() {\n  return fetch(\"weather-endpoint\");\n}\n\nasync function main() {\n  try {\n    const response = await backOff(() =\u003e getWeather());\n    // process response\n  } catch (e) {\n    // handle error\n  }\n}\n\nmain();\n```\n\nMigrating across major versions? Here are our [breaking changes](https://github.com/coveo/exponential-backoff/tree/master/doc/migration-guide.md).\n\n### `BackOffOptions`\n\n- `delayFirstAttempt?: boolean`\n\n  Decides whether the `startingDelay` should be applied before the first call. If `false`, the first call will occur without a delay.\n\n  Default value is `false`.\n\n- `jitter?: JitterType | string`\n\n  Decides whether a [jitter](https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/) should be applied to the delay. Possible values are `full` and `none`.\n\n  Default value is `none`.\n\n- `maxDelay?: number`\n\n  The maximum delay, in milliseconds, between two consecutive attempts.\n\n  Default value is `Infinity`.\n\n- `numOfAttempts?: number`\n\n  The maximum number of times to attempt the function.\n\n  Default value is `10`.\n\n  Minimum value is `1`.\n\n- `retry?: (e: any, attemptNumber: number) =\u003e boolean | Promise\u003cboolean\u003e`\n\n  The `retry` function can be used to run logic after every failed attempt (e.g. logging a message, assessing the last error, etc.). It is called with the last error and the upcoming attempt number. Returning `true` will retry the function as long as the `numOfAttempts` has not been exceeded. Returning `false` will end the execution.\n\n  Default value is a function that always returns `true`.\n\n- `startingDelay?: number`\n\n  The delay, in milliseconds, before executing the function for the first time.\n\n  Default value is `100` ms.\n\n- `timeMultiple?: number`\n\n  The `startingDelay` is multiplied by the `timeMultiple` to increase the delay between reattempts.\n\n  Default value is `2`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoveooss%2Fexponential-backoff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoveooss%2Fexponential-backoff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoveooss%2Fexponential-backoff/lists"}