{"name":"exponential-backoff","version":"3.1.2","keywords":["exponential","backoff","retry"],"author":{"name":"Sami Sayegh"},"license":"Apache-2.0","_id":"exponential-backoff@3.1.2","homepage":"https://github.com/coveooss/exponential-backoff#readme","bugs":{"url":"https://github.com/coveooss/exponential-backoff/issues"},"dist":{"shasum":"a8f26adb96bf78e8cd8ad1037928d5e5c0679d91","tarball":"http://registry-npm.ywwl.com/exponential-backoff/download/exponential-backoff-3.1.2.tgz","fileCount":47,"integrity":"sha512-8QxYTVXUkuy7fIIoitQkPwGonB8F3Zj8eEO8Sqg9Zv/bkI7RJAzowee4gr81Hak/dUTpA2Z7VfQgoijjPNlUZA==","signatures":[{"sig":"MEUCIQDXtDHccfW6MV3a9t7Ik5smSFowOr+2WQjShMA/o7cC2QIgZFWlZJF0sATjZiWt6eAx6MOC9lRnzbZt3t44wuHBPJg=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/exponential-backoff@3.1.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":55183,"size":15150,"noattachment":false,"key":"/exponential-backoff/-/exponential-backoff-3.1.2.tgz"},"jest":{"testRegex":"\\.spec\\.ts$","transform":{"^.+\\.ts$":"ts-jest"},"moduleFileExtensions":["ts","js"]},"main":"dist/backoff.js","husky":{"hooks":{"pre-commit":"lint-staged"}},"types":"dist/backoff.d.ts","gitHead":"70bdff6d7e21d5d30de874df5d0e16511f147f1d","scripts":{"test":"jest","build":"tsc","test:watch":"jest --watch"},"_npmUser":{"name":"sssayegh","email":"ssayegh@coveo.com"},"repository":{"url":"git+https://github.com/coveooss/exponential-backoff.git","type":"git"},"_npmVersion":"10.8.2","description":"A utility that allows retrying a function with an exponential delay between attempts.","directories":{},"lint-staged":{"*.{ts,json,md}":["prettier --write","git add"]},"_nodeVersion":"18.20.6","_hasShrinkwrap":false,"devDependencies":{"jest":"^24.9.0","husky":"^3.0.9","ts-jest":"^24.1.0","prettier":"^1.18.2","typescript":"^3.6.4","@types/jest":"^24.0.18","@types/node":"^10.14.21","lint-staged":"^9.4.2"},"_npmOperationalInternal":{"tmp":"tmp/exponential-backoff_3.1.2_1738872356331_0.8379364145477888","host":"s3://npm-registry-packages-npm-production"},"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<T>` function takes a promise-returning function to retry, and an optional `BackOffOptions` object. It returns a `Promise<T>`.\n\n```ts\nfunction backOff<T>(\n  request: () => Promise<T>,\n  options?: BackOffOptions\n): Promise<T>;\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(() => 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) => boolean | Promise<boolean>`\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","publish_time":1738872356530,"maintainers":[{"email":"aboissinot@coveo.com","name":"aboissinot"},{"email":"lcoolen@coveo.com","name":"lcoolen"},{"email":"sandbox_JSUI@coveo.com","name":"coveo-organization"},{"email":"itaccounts@coveo.com","name":"coveoit"},{"email":"olamothe@coveo.com","name":"olamothe"},{"email":"ssayegh@coveo.com","name":"sssayegh"},{"email":"ylakhdar@coveo.com","name":"ylakhdar"},{"email":"agong@coveo.com","name":"agong-coveo"},{"email":"ndlabarre@coveo.com","name":"ndlr"},{"email":"npmcoveo@coveo.com","name":"npmcoveo"},{"email":"lbompart@coveo.com","name":"pixhel"},{"email":"mmitiche@coveo.com","name":"mmitiche"},{"email":"nlegros@coveo.com","name":"nlegros"},{"email":"sallain@coveo.com","name":"sallain"},{"email":"msrioux@coveo.com","name":"msrioux"},{"email":"talao@coveo.com","name":"talao-coveo"}],"_cnpm_publish_time":1738872356530,"dist-tags":{"latest":"3.1.3"}}