{"_id":"@alvarocastro/backoff","_rev":"1-6343aff1aa5ad39e1e6f77c9139cf03c","name":"@alvarocastro/backoff","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.1":{"name":"@alvarocastro/backoff","version":"1.0.1","description":"Simple implementation of a backoff utility","main":"index.js","scripts":{"test":"xo && nyc ava"},"repository":{"type":"git","url":"git+https://github.com/alvarocastro/backoff.git"},"publishConfig":{"access":"public"},"keywords":["backoff","delay"],"author":{"name":"Alvaro Castro"},"license":"MIT","bugs":{"url":"https://github.com/alvarocastro/backoff/issues"},"homepage":"https://github.com/alvarocastro/backoff#readme","devDependencies":{"ava":"3.13.0","coveralls":"3.1.0","nyc":"15.1.0","semantic-release":"^17.1.2","xo":"0.35.0"},"gitHead":"5dae64ce2f10423a3ec2bb9d9fb603cf1bb0c470","_id":"@alvarocastro/backoff@1.0.1","_nodeVersion":"10.23.0","_npmVersion":"6.14.9","dist":{"integrity":"sha512-O96aiukCqUmdJ+dTzU5OSXoyOSkMQ0gVfvTrLar1QBLld8/87jqVji8jL23Cq/ZjQ423iXXHM7HPyTDp76yf8Q==","shasum":"b83bea565b91681714eb4cd514c81da729b89be3","tarball":"https://registry.npmjs.org/@alvarocastro/backoff/-/backoff-1.0.1.tgz","fileCount":8,"unpackedSize":8331,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfvPrBCRA9TVsSAnZWagAADEsP/0+Pk3vhicAPvs1ViLtz\npkAsCSUeWFV2WbeOOkTRQ36CeYOcGNjX0LSddr6axVczf1j+5DQu0V5Wqxwj\nxyxIabaxJOGtxsdgLcxpwlLgUAYmFOqiMRTmMmnhUSpx/D13KFcB/AFmRyUE\njJUPYFOOx7WaEBdqX7KP7+aTbcIKUrMkI0UqttC5A6WBTOCwDUmPbUrV6fwo\nlmQTwx1P4jMg6TEllSlkCAz4aANMtln/suBCx69PZPAylP9As1lsonqGEMIA\nDKjvWLQjgMD25yNoIbbUeh35hN2ZZTPkRE82Ixb9YxPNCikOVcM8oWNAvzfC\nssBoV5fg0bDYpUXGjilVLCZeokEhecB3+6ZNLgV+Jz+9iOiZjyk1CSduhrqf\nDXfYrywJoO+XL1dlgr8IfxM5SKxU/2/9cdou6pYPlbLZJugVRta7YEe8IK3m\njcXD+z9G6WWS6oFpq3ZZwScqhQBw1Q62EaRn5DCFZiPDT/Qs6AwKu5UI09iW\nsFDLfZRZ+eGBMVHvqvYbLXkv4rQ39mMldYfnmsdPDB/Xu8uSQyKRumdBQcxu\nXv0WGUMPyJhm5f4XXIIkZcU7O8FTwv7E2KB+Ppqac8l65FxcAKzdfmiOSC+d\nJmpF9ZtU4xU23r+O8uHQbo4GfYLdR7Ed+PJsT+yFGIFxUTUR0m78IwqkrffZ\nbrtU\r\n=/1ll\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAcdXH02b2eJyFTda1BPBMJ61lrTaQmMvvlU6OmQIUxOAiBo80FsdaE4w4bjBq7HL3+nqM1bYKYh+4zNfvfTfLmxTg=="}]},"_npmUser":{"name":"alvarocastro","email":"moltar89@gmail.com"},"directories":{},"maintainers":[{"name":"alvarocastro","email":"moltar89@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/backoff_1.0.1_1606220481326_0.031719387487273654"},"_hasShrinkwrap":false}},"time":{"created":"2020-11-24T12:21:21.266Z","1.0.1":"2020-11-24T12:21:21.455Z","modified":"2022-04-04T13:41:43.430Z"},"maintainers":[{"name":"alvarocastro","email":"moltar89@gmail.com"}],"description":"Simple implementation of a backoff utility","homepage":"https://github.com/alvarocastro/backoff#readme","keywords":["backoff","delay"],"repository":{"type":"git","url":"git+https://github.com/alvarocastro/backoff.git"},"author":{"name":"Alvaro Castro"},"bugs":{"url":"https://github.com/alvarocastro/backoff/issues"},"license":"MIT","readme":"# Backoff\n\n[![NPM](https://img.shields.io/npm/v/@alvarocastro/backoff)](https://www.npmjs.com/package/@alvarocastro/backoff)\n[![Build status](https://img.shields.io/github/workflow/status/alvarocastro/backoff/build)](https://github.com/alvarocastro/backoff/actions?query=workflow%3Abuild)\n[![Maintainability status](https://img.shields.io/codeclimate/maintainability/alvarocastro/backoff)](https://codeclimate.com/github/alvarocastro/backoff/maintainability)\n[![Coverage status](https://img.shields.io/coveralls/github/alvarocastro/backoff)](https://coveralls.io/github/alvarocastro/backoff?branch=master)\n[![Bundle size](https://img.shields.io/bundlephobia/min/@alvarocastro/backoff)](https://bundlephobia.com/result?p=@alvarocastro/backoff)\n[![Code style: XO](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/xojs/xo)\n[![Release: Semantic](https://img.shields.io/badge/%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n\nA simple implementation of a backoff utility.\n\n- [Install](#install)\n- [Usage](#usage)\n- [Contributing](#contributing)\n- [Support](#support)\n\n## Install\n\n```bash\nnpm install @alvarocastro/backoff\n```\n\n## Usage\n\n```js\nconst Backoff = require('@alvarocastro/backoff');\nconst backoff = new Backoff();\n\nconst connect = function () {\n\tconsole.log('Connecting...');\n\tconst rand = Math.random();\n\n\tif (rand < 0.2) {\n\t\tconsole.log('Success!');\n\t\tbackoff.reset();\n\t\treturn true;\n\t}\n\t\n\tconst delay = backoff.duration();\n\tconsole.log(`Failed. Retrying in ${delay}ms`);\n\tsetTimeout(function () {\n\t\tconnect();\n\t}, delay);\n};\n\nconnect();\n```\n\n### Backoff(options = {min: 1000, max: 60000, factor: 2, jitter: 0})\n\nReceives an optional `options` object.\n\n#### options.min\n\nType: `Number`<br>\nDefault: 1000\n\nMinimum duration.\n\n#### options.max\n\nType: `Number`<br>\nDefault: 6000\n\nMaximum duration.\n\n#### options.factor\n\nType: `Number`<br>\nDefault: 2\n\nFactor in which the duration increases each time.\n\n#### options.jitter\n\nType: `Number`<br>\nDefault: 0\n\nRandomizes the duration. For example with a value of `0.5` the initial default duration will be between 500 and 1500.\nThe randomization when used in a reconnection helps smooth the load induced by the reconnection attempts of multiple clients, in case a server goes down.\nUse `0` for no randomization.\n\n### duration()\n\nReturns the next time to wait in milliseconds.\n\n### reset()\n\nResets the internal attempts count, bringing the next `duration()` time back to the starting value.\n\n## Contributing\n\nContributions are always welcome! Please run `npm test` beforehand to ensure everything is ok.\n\n## Support\n\nIf you use this package please consider starring it :)\n","readmeFilename":"README.md"}