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 2.1.1 to 2.2.0

3

dist/backoff.js
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());

@@ -8,0 +9,0 @@ });

@@ -7,3 +7,3 @@ import { IDelay } from "./delay.interface";

constructor(options: IBackOffOptions);
apply(): Promise<{}>;
apply(): Promise<unknown>;
setAttemptNumber(attempt: number): void;

@@ -10,0 +10,0 @@ private readonly jitteredDelay;

@@ -29,3 +29,4 @@ "use strict";

var power = this.numOfDelayedAttempts;
return constant * Math.pow(base, power);
var delay = constant * Math.pow(base, power);
return Math.min(delay, this.options.maxDelay);
},

@@ -32,0 +33,0 @@ enumerable: true,

export interface IDelay {
apply: () => Promise<{}>;
apply: () => Promise<unknown>;
setAttemptNumber: (attempt: number) => void;
}
import { Delay } from "../delay.base";
export declare class SkipFirstDelay extends Delay {
apply(): Promise<true | {}>;
apply(): Promise<unknown>;
private readonly isFirstAttempt;
protected readonly numOfDelayedAttempts: number;
}

@@ -16,6 +16,7 @@ "use strict";

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());

@@ -22,0 +23,0 @@ });

@@ -8,7 +8,8 @@ export declare enum JitterTypes {

jitter: JitterTypes;
maxDelay: number;
numOfAttempts: number;
retry: (e: any, attemptNumber: number) => boolean;
startingDelay: number;
timeMultiple: number;
startingDelay: number;
}
export declare function getSanitizedOptions(options: Partial<IBackOffOptions>): IBackOffOptions;

@@ -22,9 +22,10 @@ "use strict";

jitter: JitterTypes.None,
maxDelay: Infinity,
numOfAttempts: 10,
retry: function () { return true; },
numOfAttempts: 10,
timeMultiple: 2,
startingDelay: 100
startingDelay: 100,
timeMultiple: 2
};
function getSanitizedOptions(options) {
var sanitized = __assign({}, defaultOptions, options);
var sanitized = __assign(__assign({}, defaultOptions), options);
if (sanitized.numOfAttempts < 1) {

@@ -31,0 +32,0 @@ sanitized.numOfAttempts = 1;

{
"name": "exponential-backoff",
"version": "2.1.1",
"version": "2.2.0",
"description": "A utility that allows retrying a function with an exponential delay between attempts.",

@@ -49,11 +49,11 @@ "main": "dist/backoff.js",

"devDependencies": {
"@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"
"@types/jest": "^24.0.18",
"@types/node": "^10.14.21",
"husky": "^3.0.9",
"jest": "^24.9.0",
"lint-staged": "^9.4.2",
"prettier": "^1.18.2",
"ts-jest": "^24.1.0",
"typescript": "^3.6.4"
}
}

@@ -13,8 +13,30 @@ # exponential-backoff

The generic `backOff<T>` function takes a function `() => Promise<T>` to be retried, and an optional `IBackOffOptions` object. It returns a generic `Promise<T>`.
The `backOff<T>` function takes a promise-returning function to retry, and an optional `IBackOffOptions` object. It returns a `Promise<T>`.
```
function backOff<T>(request: () => Promise<T>, options: IBackOffOptions = {}): Promise<T>
function backOff<T>(request: () => Promise<T>, options?: IBackOffOptions): Promise<T>
```
Here is an example retrying a function that calls a hypothetical weather endpoint:
```
import { backOff } from 'exponential-backoff';
function getWeather() {
return fetch('weather-endpoint');
}
async function main() {
try {
const response = await backOff(() => getWeather());
// process response
}
catch (e) {
// handle error
}
}
main();
```
Migrating from v1 to v2? Here are our [breaking changes](https://github.com/coveo/exponential-backoff/tree/master/doc/v1-to-v2-migration.md).

@@ -36,2 +58,8 @@

- `maxDelay?: number`
The maximum delay between two consecutive attempts.
Default value is `Infinity`.
- `numOfAttempts?: number`

@@ -38,0 +66,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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