# @kenyip/backoff-strategies

> Javascript Library for Backoff/Retry Strategies with zero dependencies

Latest version **1.0.4** (published 2021-10-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install @kenyip/backoff-strategies
pnpm add @kenyip/backoff-strategies
yarn add @kenyip/backoff-strategies
bun add @kenyip/backoff-strategies
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2021-10-09 |
| First published | 2021-09-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | ken.yip |
| Maintainers | kenyip |
| Keywords | backoff, delay |

## Links

- npm: https://www.npmjs.com/package/@kenyip/backoff-strategies
- Repository: https://github.com/kenyipp/backoff-strategies
- Homepage: https://github.com/kenyipp/backoff-strategies#readme
- Issues: https://github.com/kenyipp/backoff-strategies/issues
- npm.io page: https://npm.io/package/@kenyip/backoff-strategies

## Recent versions

- 1.0.4 (latest) — 2021-10-09
- 1.0.3 — 2021-10-09
- 1.0.2 — 2021-10-09
- 1.0.1 — 2021-09-27
- 1.0.0 — 2021-09-24

## README

# Backoff Strategies
Javascript Library for Backoff/Retry Strategies with zero dependencies

## Install
```
$ npm install --save @kenyip/backoff-strategies
```

## Usage
```js
const backoffStrategies = require("@kenyip/backoff-strategies");

const backoff = backoffStrategies({
	delay: 1000,
	strategy: "fibonacci",
	jitter: false,
	minimumDelay: 1000,
	scaleFactor: 1
});

console.log(backoff(1));
// 1000

console.log(backoff(2));
// 1000

console.log(backoff(3));
// 1000

console.log(backoff(4));
// 3000
```

## API

### backoffStrategies(options?)
Returns a function that accepts number of attempt as argument and returns the milliseconds you should wait before next retry.

#### options

Type: `object`

##### delay
Type: `number`
Default: 1000

The base number of delay applied for multiply.

##### strategy
Type: `string`
Default: `fixed`

The backoff strategy applied. The default strategies include `fixed`, `exponential`, `fibonacci`, `linear` and `polynomial`.

##### jitter
Type: `boolean`
Default: false

Apply random jitter which add 0 ~ 1 seconds to the output.

##### minimumDelay
Type: `number`
Default: 0

While each strategy calculates its delay based on its own logic, you can ensure that the delay returned is always a certain minimum number of seconds. You can apply a minimum by instantiating a strategy with the minimum argument. 

##### scaleFactor
Type: `number`
Default: 1

Certain strategies - like the Polynomial strategy - can rapidly lead to very long delays between retry attempts. To offset this, while still retaining the shape of the curve between retry attempts, each strategy has a scale_factor property which is multiplied by the "“unadjusted”" delay. This can be used to reduce (or increase) the size (technically the magnitude) of the delay.

## Related
- [delay](https://www.npmjs.com/package/delay) - Delay a promise a specified amount of time

---
_Source: https://npm.io/package/@kenyip/backoff-strategies · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
