diff options
author | Kat Marchán <kzm@sykosomatic.org> | 2017-05-09 14:46:02 -0700 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2017-05-23 19:39:43 +0200 |
commit | c0d858f8bb8ba5212548da2fba6a7bc02db0462b (patch) | |
tree | 99f043ec5aec3f5150a2aed0f62597234b158140 /deps/npm/node_modules/pacote/node_modules/promise-retry/README.md | |
parent | 994617370e8e66f3ea9488fec32fd912e7902396 (diff) | |
download | android-node-v8-c0d858f8bb8ba5212548da2fba6a7bc02db0462b.tar.gz android-node-v8-c0d858f8bb8ba5212548da2fba6a7bc02db0462b.tar.bz2 android-node-v8-c0d858f8bb8ba5212548da2fba6a7bc02db0462b.zip |
deps: upgrade npm beta to 5.0.0-beta.56
PR-URL: https://github.com/nodejs/node/pull/12936
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'deps/npm/node_modules/pacote/node_modules/promise-retry/README.md')
-rw-r--r-- | deps/npm/node_modules/pacote/node_modules/promise-retry/README.md | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/deps/npm/node_modules/pacote/node_modules/promise-retry/README.md b/deps/npm/node_modules/pacote/node_modules/promise-retry/README.md new file mode 100644 index 0000000000..85c3bc57e8 --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/promise-retry/README.md @@ -0,0 +1,92 @@ +# node-promise-retry + +[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency status][david-dm-image]][david-dm-url] [![Dev Dependency status][david-dm-dev-image]][david-dm-dev-url] + +[npm-url]:https://npmjs.org/package/promise-retry +[downloads-image]:http://img.shields.io/npm/dm/promise-retry.svg +[npm-image]:http://img.shields.io/npm/v/promise-retry.svg +[travis-url]:https://travis-ci.org/IndigoUnited/node-promise-retry +[travis-image]:http://img.shields.io/travis/IndigoUnited/node-promise-retry/master.svg +[david-dm-url]:https://david-dm.org/IndigoUnited/node-promise-retry +[david-dm-image]:https://img.shields.io/david/IndigoUnited/node-promise-retry.svg +[david-dm-dev-url]:https://david-dm.org/IndigoUnited/node-promise-retry#info=devDependencies +[david-dm-dev-image]:https://img.shields.io/david/dev/IndigoUnited/node-promise-retry.svg + +Retries a function that returns a promise, leveraging the power of the [retry](https://github.com/tim-kos/node-retry) module to the promises world. + +There's already some modules that are able to retry functions that return promises but +they were rather difficult to use or do not offer an easy way to do conditional retries. + + +## Installation + +`$ npm install promise-retry` + + +## Usage + +### promiseRetry(fn, [options]) + +Calls `fn` until the returned promise ends up fulfilled or rejected with an error different than +a `retry` error. +The `options` argument is an object which maps to the [retry](https://github.com/tim-kos/node-retry) module options: + +- `retries`: The maximum amount of times to retry the operation. Default is `10`. +- `factor`: The exponential factor to use. Default is `2`. +- `minTimeout`: The number of milliseconds before starting the first retry. Default is `1000`. +- `maxTimeout`: The maximum number of milliseconds between two retries. Default is `Infinity`. +- `randomize`: Randomizes the timeouts by multiplying with a factor between `1` to `2`. Default is `false`. + + +The `fn` function will receive a `retry` function as its first argument that should be called with an error whenever you want to retry `fn`. The `retry` function will always throw an error. +If there's retries left, it will throw a special `retry` error that will be handled internally to call `fn` again. +If there's no retries left, it will throw the actual error passed to it. + +If you prefer, you can pass the options first using the alternative function signature `promiseRetry([options], fn)`. + +## Example +```js +var promiseRetry = require('promise-retry'); + +// Simple example +promiseRetry(function (retry, number) { + console.log('attempt number', number); + + return doSomething() + .catch(retry); +}) +.then(function (value) { + // .. +}, function (err) { + // .. +}); + +// Conditional example +promiseRetry(function (retry, number) { + console.log('attempt number', number); + + return doSomething() + .catch(function (err) { + if (err.code === 'ETIMEDOUT') { + retry(err); + } + + throw err; + }); +}) +.then(function (value) { + // .. +}, function (err) { + // .. +}); +``` + + +## Tests + +`$ npm test` + + +## License + +Released under the [MIT License](http://www.opensource.org/licenses/mit-license.php). |