Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

exponential-backoff

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

exponential-backoff - npm Package Compare versions

Comparing version 1.2.0 to 2.0.0

doc/v1-to-v2-migration.md

20

package.json
{
"name": "exponential-backoff",
"version": "1.2.0",
"version": "2.0.0",
"description": "A utility that allows retrying a function with an exponential delay between attempts.",

@@ -43,3 +43,3 @@ "main": "dist/backoff.js",

"author": "Sami Sayegh",
"license": "Apache 2.0",
"license": "Apache-2.0",
"bugs": {

@@ -50,11 +50,11 @@ "url": "https://github.com/coveo/exponential-backoff/issues"

"devDependencies": {
"@types/jest": "^23.1.4",
"@types/node": "^10.5.1",
"husky": "^0.14.3",
"jest": "^23.6.0",
"lint-staged": "^7.2.0",
"prettier": "^1.13.7",
"ts-jest": "^23.0.0",
"typescript": "^2.9.2"
"@types/jest": "^24.0.0",
"@types/node": "^10.12.24",
"husky": "^1.3.1",
"jest": "^24.1.0",
"lint-staged": "^8.1.3",
"prettier": "^1.16.4",
"ts-jest": "^23.10.5",
"typescript": "^3.3.3"
}
}
# exponential-backoff
A utility that allows retrying a function with an exponential delay between attempts.

@@ -11,50 +12,49 @@

## Usage
The generic `backOff<T>` function takes an `IBackOffRequest<T>` object, and an optional `IBackOffOptions` object. It returns a generic `Promise<T>`.
The generic `backOff<T>` function takes a function `() => Promise<T>` to be retried, and an optional `IBackOffOptions` object. It returns a generic `Promise<T>`.
```
function backOff<T>(request: IBackOffRequest<T>, options: Partial<IBackOffOptions> = {}): Promise<T>
function backOff<T>(request: () => Promise<T>, options: IBackOffOptions = {}): Promise<T>
```
### `IBackOffRequest<T>`
* `fn: () => Promise<T>`
Migrating from v1 to v2? Here are our [breaking changes](https://github.com/coveo/exponential-backoff/tree/master/doc/v1-to-v2-migration.md).
The function to be attempted.
### `IBackOffOptions`
* `retry?: (e, attemptNumber: number) => boolean`
Everytime `fn` returns a rejected promise, the `retry` function is called with the error and the attempt number. Returning `true` will reattempt the function as long as the `numOfAttempts` has not been exceeded. Returning `false` will end the execution.
Default value is a function that always returns `true`.
- `delayFirstAttempt?: boolean`
### `IBackOffOptions`
* `delayFirstAttempt?: boolean`
Decides whether the `startingDelay` should be applied before the first call. If `false`, the first call will occur without a delay.
Decides whether the `startingDelay` should be applied before the first call to `fn`. If `false`, the first call to `fn` will occur without a delay.
Default value is `false`.
Default value is `true`.
- `jitter?: JitterType | string`
* `jitter?: JitterType | string`
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`.
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`.
Default value is `none`.
Default value is `none`.
- `numOfAttempts?: number`
* `numOfAttempts?: number`
The maximum number of times to attempt the function.
The maximum number of times to attempt the function.
Default value is `10`.
Minimum value is `1`.
Default value is `10`.
* `startingDelay?: number`
Minimum value is `1`.
The delay before executing the function for the first time.
Default value is `100` ms.
- `retry?: (e: any, attemptNumber: number) => boolean`
* `timeMultiple?: number`
Everytime the function returns a rejected promise, the `retry` function is called with the error and the attempt number. Returning `true` will reattempt the function as long as the `numOfAttempts` has not been exceeded. Returning `false` will end the execution.
The `startingDelay` is multiplied by the `timeMultiple` value to increase the delay between reattempts.
Default value is `2`.
Default value is a function that always returns `true`.
- `startingDelay?: number`
The delay before executing the function for the first time.
Default value is `100` ms.
- `timeMultiple?: number`
The `startingDelay` is multiplied by the `timeMultiple` to increase the delay between reattempts.
Default value is `2`.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc