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.2.1 to 3.0.0

doc/migration-guide.md

5

dist/jitter/jitter.factory.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var options_1 = require("../options");
var full_jitter_1 = require("./full/full.jitter");

@@ -8,5 +7,5 @@ var no_jitter_1 = require("./no/no.jitter");

switch (options.jitter) {
case options_1.JitterTypes.Full:
case "full":
return full_jitter_1.fullJitter;
case options_1.JitterTypes.None:
case "none":
default:

@@ -13,0 +12,0 @@ return no_jitter_1.noJitter;

7

dist/options.d.ts

@@ -1,8 +0,5 @@

export declare enum JitterTypes {
None = "none",
Full = "full"
}
export declare type JitterType = "none" | "full";
export interface IBackOffOptions {
delayFirstAttempt: boolean;
jitter: JitterTypes;
jitter: JitterType;
maxDelay: number;

@@ -9,0 +6,0 @@ numOfAttempts: number;

@@ -14,10 +14,5 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var JitterTypes;
(function (JitterTypes) {
JitterTypes["None"] = "none";
JitterTypes["Full"] = "full";
})(JitterTypes = exports.JitterTypes || (exports.JitterTypes = {}));
var defaultOptions = {
delayFirstAttempt: false,
jitter: JitterTypes.None,
jitter: "none",
maxDelay: Infinity,

@@ -24,0 +19,0 @@ numOfAttempts: 10,

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

@@ -5,0 +5,0 @@ "main": "dist/backoff.js",

@@ -16,3 +16,6 @@ # exponential-backoff

```ts
function backOff<T>(request: () => Promise<T>, options?: IBackOffOptions): Promise<T>
function backOff<T>(
request: () => Promise<T>,
options?: IBackOffOptions
): Promise<T>;
```

@@ -23,16 +26,15 @@

```js
import { backOff } from 'exponential-backoff';
import { backOff } from "exponential-backoff";
function getWeather() {
return fetch('weather-endpoint');
return fetch("weather-endpoint");
}
async function main() {
try {
const response = await backOff(() => getWeather());
// process response
}
catch (e) {
// handle error
}
try {
const response = await backOff(() => getWeather());
// process response
} catch (e) {
// handle error
}
}

@@ -43,3 +45,3 @@

Migrating from v1 to v2? Here are our [breaking changes](https://github.com/coveo/exponential-backoff/tree/master/doc/v1-to-v2-migration.md).
Migrating across major versions? Here are our [breaking changes](https://github.com/coveo/exponential-backoff/tree/master/doc/migration-guide.md).

@@ -76,3 +78,3 @@ ### `IBackOffOptions`

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 `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.

@@ -79,0 +81,0 @@ Default value is a function that always returns `true`.

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