{"_id":"async-retry-ng","_rev":"4298133","name":"async-retry-ng","description":"Retrying made simple, easy and async","dist-tags":{"latest":"2.0.2"},"maintainers":[{"name":"jamo","email":"jamo@isotalo.fi"},{"name":"olliv","email":"olli@zeit.co"}],"time":{"modified":"2026-04-07T21:03:42.000Z","created":"2019-12-15T00:31:14.177Z","2.0.2":"2024-12-31T09:35:26.027Z","2.0.1":"2020-05-13T18:05:44.642Z","2.0.0":"2020-03-22T20:17:09.302Z","1.0.2":"2020-02-23T20:13:55.785Z","1.0.1":"2019-12-15T00:40:29.271Z","1.0.0":"2019-12-15T00:31:14.177Z"},"users":{},"repository":{"type":"git","url":"git+https://github.com/turist-cloud/async-retry-ng.git"},"versions":{"2.0.2":{"name":"async-retry-ng","version":"2.0.2","description":"Retrying made simple, easy and async","main":"./lib/index.js","scripts":{"test":"jest --testTimeout 20000","prettier":"prettier --single-quote --write './{src,__tests__}/**/*.js'"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/turist-cloud/async-retry-ng.git"},"devDependencies":{"jest":"29.7.0","node-fetch":"2.6.7","prettier":"3.4.2","then-sleep":"1.0.1"},"_id":"async-retry-ng@2.0.2","gitHead":"4826740c02d684f9c7343b712f6c280834e16dbd","types":"./lib/index.d.ts","bugs":{"url":"https://github.com/turist-cloud/async-retry-ng/issues"},"homepage":"https://github.com/turist-cloud/async-retry-ng#readme","_nodeVersion":"20.11.1","_npmVersion":"10.2.4","dist":{"shasum":"c46db8fc6f67b75079c373381e64bfea53a0f298","size":4977,"noattachment":false,"key":"/async-retry-ng/-/async-retry-ng-2.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/async-retry-ng/download/async-retry-ng-2.0.2.tgz"},"_npmUser":{"name":"olliv","email":"olli.vanhoja@gmail.com"},"directories":{},"maintainers":[{"name":"jamo","email":"jamo@isotalo.fi"},{"name":"olliv","email":"olli@zeit.co"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/async-retry-ng_2.0.2_1735637725848_0.0012143795184662576"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2024-12-31T09:35:26.027Z","publish_time":1735637726027,"_source_registry_name":"default","_cnpm_publish_time":1735637726027},"2.0.1":{"name":"async-retry-ng","version":"2.0.1","description":"Retrying made simple, easy and async","main":"./lib/index.js","scripts":{"test":"yarn run test-lint && yarn run test-unit","test-lint":"eslint .","test-unit":"jest --testTimeout 20000","lint:staged":"lint-staged","prettier":"prettier --single-quote --write './{src,__tests__}/**/*.js'"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/turist-cloud/async-retry-ng.git"},"pre-commit":"lint:staged","lint-staged":{"*.js":["eslint","prettier --write --single-quote"]},"eslintConfig":{"plugins":["jest"],"extends":["plugin:jest/recommended","airbnb","prettier"],"rules":{"no-param-reassign":0,"no-plusplus":0,"no-restricted-properties":0,"no-restricted-syntax":0,"no-underscore-dangle":0,"prefer-arrow-callback":0}},"devDependencies":{"eslint":"6.8.0","eslint-config-airbnb":"18.1.0","eslint-config-prettier":"6.10.1","eslint-plugin-import":"2.20.1","eslint-plugin-jest":"23.8.2","eslint-plugin-jsx-a11y":"6.2.3","eslint-plugin-react":"7.19.0","eslint-plugin-react-hooks":"2.5.1","jest":"25.1.0","lint-staged":"10.0.8","node-fetch":"2.6.0","pre-commit":"1.2.2","prettier":"2.0.1","then-sleep":"1.0.1"},"gitHead":"0118cbe966384413af29c4d897af3d8e707003cf","bugs":{"url":"https://github.com/turist-cloud/async-retry-ng/issues"},"homepage":"https://github.com/turist-cloud/async-retry-ng#readme","_id":"async-retry-ng@2.0.1","_nodeVersion":"12.16.1","_npmVersion":"6.13.4","dist":{"shasum":"f5285ec1c52654a2ba6a505d0c18b1eadfaebd41","size":5278,"noattachment":false,"key":"/async-retry-ng/-/async-retry-ng-2.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/async-retry-ng/download/async-retry-ng-2.0.1.tgz"},"maintainers":[{"name":"jamo","email":"jamo@isotalo.fi"},{"name":"olliv","email":"olli@zeit.co"}],"_npmUser":{"name":"olliv","email":"olli.vanhoja@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/async-retry-ng_2.0.1_1589393144529_0.7382248674109471"},"_hasShrinkwrap":false,"publish_time":1589393144642,"_cnpm_publish_time":1589393144642},"2.0.0":{"name":"async-retry-ng","version":"2.0.0","description":"Retrying made simple, easy and async","main":"./lib/index.js","scripts":{"test":"yarn run test-lint && yarn run test-unit","test-lint":"eslint .","test-unit":"jest --testTimeout 20000","lint:staged":"lint-staged","prettier":"prettier --single-quote --write './{src,__tests__}/**/*.js'"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/turist-cloud/async-retry-ng.git"},"pre-commit":"lint:staged","lint-staged":{"*.js":["eslint","prettier --write --single-quote"]},"eslintConfig":{"plugins":["jest"],"extends":["plugin:jest/recommended","airbnb","prettier"],"rules":{"no-param-reassign":0,"no-plusplus":0,"no-restricted-properties":0,"no-restricted-syntax":0,"no-underscore-dangle":0,"prefer-arrow-callback":0}},"devDependencies":{"eslint":"6.8.0","eslint-config-airbnb":"18.1.0","eslint-config-prettier":"6.10.1","eslint-plugin-import":"2.20.1","eslint-plugin-jest":"23.8.2","eslint-plugin-jsx-a11y":"6.2.3","eslint-plugin-react":"7.19.0","eslint-plugin-react-hooks":"2.5.1","jest":"25.1.0","lint-staged":"10.0.8","node-fetch":"2.6.0","pre-commit":"1.2.2","prettier":"2.0.1","then-sleep":"1.0.1"},"gitHead":"73c44b469f56225624ff5479d3a5a8178b83e5e3","bugs":{"url":"https://github.com/turist-cloud/async-retry-ng/issues"},"homepage":"https://github.com/turist-cloud/async-retry-ng#readme","_id":"async-retry-ng@2.0.0","_nodeVersion":"12.16.1","_npmVersion":"6.13.4","dist":{"shasum":"2a1b71f45b1339cc4a24da7150fa58e9a0c405ad","size":5274,"noattachment":false,"key":"/async-retry-ng/-/async-retry-ng-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/async-retry-ng/download/async-retry-ng-2.0.0.tgz"},"maintainers":[{"name":"jamo","email":"jamo@isotalo.fi"},{"name":"olliv","email":"olli@zeit.co"}],"_npmUser":{"name":"olliv","email":"olli.vanhoja@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/async-retry-ng_2.0.0_1584908229180_0.0532300580419387"},"_hasShrinkwrap":false,"publish_time":1584908229302,"_cnpm_publish_time":1584908229302},"1.0.2":{"name":"async-retry-ng","version":"1.0.2","description":"Retrying made simple, easy and async","main":"./lib/index.js","scripts":{"test":"yarn run test-lint && yarn run test-unit","test-lint":"eslint .","test-unit":"jest --testTimeout 20000","lint:staged":"lint-staged"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/olliv/async-retry-ng.git"},"pre-commit":"lint:staged","lint-staged":{"*.js":["eslint","prettier --write --single-quote","git add"]},"eslintConfig":{"plugins":["jest"],"extends":["plugin:jest/recommended","airbnb","prettier"],"rules":{"prefer-arrow-callback":0,"no-underscore-dangle":0}},"devDependencies":{"eslint":"6.7.2","eslint-config-airbnb":"18.0.1","eslint-config-prettier":"6.7.0","eslint-plugin-import":"2.19.1","eslint-plugin-jest":"23.1.1","eslint-plugin-jsx-a11y":"6.2.3","eslint-plugin-react":"7.14.3","eslint-plugin-react-hooks":"1.7.0","jest":"24.9.0","lint-staged":"9.5.0","node-fetch":"2.6.0","pre-commit":"1.2.2","prettier":"1.19.1","then-sleep":"1.0.1"},"gitHead":"db4bc509a3d01940042e7e8eb5ea8f41e425e2de","bugs":{"url":"https://github.com/olliv/async-retry-ng/issues"},"homepage":"https://github.com/olliv/async-retry-ng#readme","_id":"async-retry-ng@1.0.2","_nodeVersion":"12.11.1","_npmVersion":"6.11.3","dist":{"shasum":"eb9d8313af649404d4cf862075f662f29b05c510","size":5167,"noattachment":false,"key":"/async-retry-ng/-/async-retry-ng-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/async-retry-ng/download/async-retry-ng-1.0.2.tgz"},"maintainers":[{"name":"jamo","email":"jamo@isotalo.fi"},{"name":"olliv","email":"olli@zeit.co"}],"_npmUser":{"name":"olliv","email":"olli.vanhoja@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/async-retry-ng_1.0.2_1582488835620_0.8394478324357879"},"_hasShrinkwrap":false,"publish_time":1582488835785,"_cnpm_publish_time":1582488835785},"1.0.1":{"name":"async-retry-ng","version":"1.0.1","description":"Retrying made simple, easy and async","main":"./lib/index.js","scripts":{"test":"yarn run test-lint && yarn run test-unit","test-lint":"eslint .","test-unit":"jest --testTimeout 20000","lint:staged":"lint-staged"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/olliv/async-retry-ng.git"},"pre-commit":"lint:staged","lint-staged":{"*.js":["eslint","prettier --write --single-quote","git add"]},"eslintConfig":{"plugins":["jest"],"extends":["plugin:jest/recommended","airbnb","prettier"],"rules":{"prefer-arrow-callback":0,"no-underscore-dangle":0}},"devDependencies":{"eslint":"6.7.2","eslint-config-airbnb":"18.0.1","eslint-config-prettier":"6.7.0","eslint-plugin-import":"2.19.1","eslint-plugin-jest":"23.1.1","eslint-plugin-jsx-a11y":"6.2.3","eslint-plugin-react":"7.14.3","eslint-plugin-react-hooks":"1.7.0","jest":"24.9.0","lint-staged":"9.5.0","node-fetch":"2.6.0","pre-commit":"1.2.2","prettier":"1.19.1","then-sleep":"1.0.1"},"gitHead":"955833a2ed0bb56c37f02d47240fa4f04a6aa587","bugs":{"url":"https://github.com/olliv/async-retry-ng/issues"},"homepage":"https://github.com/olliv/async-retry-ng#readme","_id":"async-retry-ng@1.0.1","_nodeVersion":"12.11.1","_npmVersion":"6.11.3","dist":{"shasum":"b8a316b26992e8d514c5019439d9791c1c6f4431","size":5164,"noattachment":false,"key":"/async-retry-ng/-/async-retry-ng-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/async-retry-ng/download/async-retry-ng-1.0.1.tgz"},"maintainers":[{"name":"jamo","email":"jamo@isotalo.fi"},{"name":"olliv","email":"olli@zeit.co"}],"_npmUser":{"name":"olliv","email":"olli.vanhoja@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/async-retry-ng_1.0.1_1576370429150_0.49559425838833837"},"_hasShrinkwrap":false,"publish_time":1576370429271,"_cnpm_publish_time":1576370429271},"1.0.0":{"name":"async-retry-ng","version":"1.0.0","description":"Retrying made simple, easy and async","main":"./lib/index.js","scripts":{"test":"yarn run test-lint && yarn run test-unit","test-lint":"eslint .","test-unit":"jest --testTimeout 20000","lint:staged":"lint-staged"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/olliv/async-retry-ng.git"},"pre-commit":"lint:staged","lint-staged":{"*.js":["eslint","prettier --write --single-quote","git add"]},"eslintConfig":{"plugins":["jest"],"extends":["plugin:jest/recommended","airbnb","prettier"],"rules":{"prefer-arrow-callback":0,"no-underscore-dangle":0}},"devDependencies":{"eslint":"6.7.2","eslint-config-airbnb":"18.0.1","eslint-config-prettier":"6.7.0","eslint-plugin-import":"2.19.1","eslint-plugin-jest":"23.1.1","eslint-plugin-jsx-a11y":"6.2.3","eslint-plugin-react":"7.14.3","eslint-plugin-react-hooks":"1.7.0","jest":"24.9.0","lint-staged":"9.5.0","node-fetch":"2.6.0","pre-commit":"1.2.2","prettier":"1.19.1","then-sleep":"1.0.1"},"gitHead":"eb8f44b50ca4c267a0f2f9f0ce41d8c74da7ca8d","bugs":{"url":"https://github.com/olliv/async-retry-ng/issues"},"homepage":"https://github.com/olliv/async-retry-ng#readme","_id":"async-retry-ng@1.0.0","_nodeVersion":"12.11.1","_npmVersion":"6.11.3","dist":{"shasum":"b91710e16a28bdaf6068277ec8c9418b388d4dc0","size":4863,"noattachment":false,"key":"/async-retry-ng/-/async-retry-ng-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/async-retry-ng/download/async-retry-ng-1.0.0.tgz"},"maintainers":[{"name":"jamo","email":"jamo@isotalo.fi"},{"name":"olliv","email":"olli@zeit.co"}],"_npmUser":{"name":"olliv","email":"olli.vanhoja@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/async-retry-ng_1.0.0_1576369873996_0.3677785333012602"},"_hasShrinkwrap":false,"publish_time":1576369874177,"_cnpm_publish_time":1576369874177}},"readme":"# async-retry-ng\n\n[![Code Style](https://badgen.net/badge/code%20style/airbnb/fd5c63)](https://github.com/airbnb/javascript)\n\nRetrying made simple, easy, and async.\n\n## Usage\n\n```js\n// Packages\nconst retry = require('async-retry-ng')\nconst fetch = require('node-fetch')\n\nawait retry(async bail => {\n  // if anything throws, we retry\n  const res = await fetch('https://google.com')\n\n  if (403 === res.status) {\n    // don't retry upon 403\n    bail(new Error('Unauthorized'))\n    return\n  }\n\n  const data = await res.text()\n  return data.substr(0, 500)\n}, {\n  retries: 5\n})\n```\n\n### API\n\n```js\nretry(retrier : Function, opts : Object) => Promise\n```\n\n- The supplied function can be `async` or not. In other words, it can be a function that returns a `Promise` or a value.\n- The supplied function receives two parameters\n  1. A `Function` you can invoke to abort the retrying (bail)\n  2. A `Number` identifying the attempt. The absolute first attempt (before any retries) is `1`.\n- The `opts`\n  * `retries`: The maximum amount of times to retry the operation. Default is `10`.\n  * `factor`: The exponential factor to use. Default is `2`.\n  * `minTimeout`: The number of milliseconds before starting the first retry. Default is `1000`.\n  * `maxTimeout`: The maximum number of milliseconds between two retries. Default is `Infinity`.\n  * `randomize`: Randomizes the timeouts by multiplying with a factor between `1` to `2`. Default is `true`.\n  * `onRetry`: an optional `Function` that is invoked after a new retry is performed. It's passed the `Error` that triggered it as a parameter.\n\nAll time values are in milliseconds.\n\n### Retries Explained\n\nThe formula used to calculate the individual timeouts is:\n\n```\nMath.min(random * minTimeout * Math.pow(factor, attempt), maxTimeout)\n```\n\nHave a look at [this article][article] for a better explanation of approach.\n\nIf you want to tune your `factor` / `times` settings to attempt the last retry\nafter a certain amount of time, you can use wolfram alpha. For example in order\nto tune for `10` attempts in `5 minutes`, you can use this equation:\n\n![screenshot](https://github.com/OlliV/async-retry-ng/raw/master/equation.gif)\n\nExplaining the various values from left to right:\n\n* `k = 0 ... 9`:  The `retries` value (10)\n* `1000`: The `minTimeout` value in ms (1000)\n* `x^k`: No need to change this, `x` will be your resulting factor\n* `5 * 60 * 1000`: The desired total amount of time for retrying in ms (5 minutes)\n\nTo make this a little easier for you, use wolfram alpha to do the calculations:\n\n<http://www.wolframalpha.com/input/?i=Sum%5B1000*x^k%2C+{k%2C+0%2C+9}%5D+%3D+5+*+60+*+1000>\n\n[article]: http://dthain.blogspot.com/2009/02/exponential-backoff-in-distributed.html\n","_attachments":{},"homepage":"https://github.com/turist-cloud/async-retry-ng#readme","bugs":{"url":"https://github.com/turist-cloud/async-retry-ng/issues"},"license":"MIT"}