@knicola/xbackoff
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

@knicola/xbackoff

JS implementation of the exponential backoff algorithm.

Install

Using npm:

$ npm install @knicola/xbackoff

Using yarn:

$ yarn add @knicola/xbackoff

Usage

xbackoff()

Create an xbackoff function

import { xbackoff, XBackoffOptions } from '@knicola/xbackoff'

// default options
const options: XBackoffOptions = {
    factor: 2,
    minTimeout: 1e3,
    maxTimeout: 60e3,
    randomize: false,
}

const getTimeout = xbackoff(options)

getTimeout(0) //=> 1000
getTimeout(1) //=> 2000
getTimeout(2) //=> 4000

compute()

Compute the timeout for the given attempt

import { compute } from '@knicola/xbackoff'

compute(0, options) //=> 1000
compute(1, options) //=> 2000
compute(2, options) //=> 4000

License

This project is open-sourced software licensed under the MIT license.

Package Sidebar

Install

npm i @knicola/xbackoff

Weekly Downloads

0

Version

0.1.1

License

MIT

Unpacked Size

8.65 kB

Total Files

9

Last publish

Collaborators

  • knicola