{"_id":"@arve.knudsen/bluebird-retry","_rev":"2-a64989d5d23954535848347115afbe89","name":"@arve.knudsen/bluebird-retry","description":"Utility for retrying a Bluebird promise until it succeeds","dist-tags":{"latest":"0.10.2"},"versions":{"0.10.2":{"name":"@arve.knudsen/bluebird-retry","version":"0.10.2","description":"Utility for retrying a Bluebird promise until it succeeds","main":"index.js","scripts":{"test":"gulp test"},"repository":{"type":"git","url":"git+https://github.com/aknuds1/bluebird-retry.git"},"keywords":["bluebird","promise","retry"],"author":{"name":"Michael Demmer","email":"demmer@jut.io"},"license":"MIT","bugs":{"url":"https://github.com/aknuds1/bluebird-retry/issues"},"homepage":"https://github.com/aknuds1/bluebird-retry","peerDependencies":{"bluebird":">=2.3.10"},"devDependencies":{"bluebird":"^3.5","browserify":"^14.0.0","chai":"^4.0","gulp":"^3.9.1","gulp-istanbul":"^1.1","gulp-mocha":"^4.3","gulp-mocha-phantomjs":"^0.12","mocha":"^3.4","requirejs":"^2.2.0","underscore":">=1.7.0","vinyl-buffer":"^1.0.0","vinyl-source-stream":"^1.1.0"},"files":["browser/*.js","index.js","lib"],"gitHead":"9a520b642dc3438f1316c4cca3440e7199d67958","_id":"@arve.knudsen/bluebird-retry@0.10.2","_shasum":"f981a00fe925fd397f8b9f054e78cb64e45a23f2","_from":".","_npmVersion":"4.1.2","_nodeVersion":"7.7.0","_npmUser":{"name":"arve.knudsen","email":"arve.knudsen@gmail.com"},"dist":{"shasum":"f981a00fe925fd397f8b9f054e78cb64e45a23f2","tarball":"https://registry.npmjs.org/@arve.knudsen/bluebird-retry/-/bluebird-retry-0.10.2.tgz","integrity":"sha512-tJT7RCA1SRAupFyyoZZSUpCbLfJrt1Ai+grxS7//2C5sQbTieFUNmCeYe1bwjDSBfzonFwNW6u1ZIcsgTvMcCA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDCkb3CtoInRwoLuvHj+SCoUOpkIwSqWw2YonExL/+8+AiB9PQBLuWEdFeDQkbXSLwN4HZ5se7VmoY+vh40TbILwYA=="}]},"maintainers":[{"name":"arve.knudsen","email":"arve.knudsen@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bluebird-retry-0.10.2.tgz_1497385140577_0.04055936448276043"}}},"readme":"# bluebird-retry [![Build Status: Linux](https://travis-ci.org/demmer/bluebird-retry.png?branch=master)](https://travis-ci.org/demmer/bluebird-retry)\n\nThis very simple library provides a function for retrying an\nasynchronous operation until it succeeds. An \"asynchronous operation\"\nis embodied by a function that returns a promise or returns synchronously.\n\nIt supports regular intervals and exponential backoff with a configurable\nlimit, as well as an overall timeout for the operation that limits the\nnumber of retries.\n\nThe bluebird library supplies the promise implementation.\n\n## Basic Usage\n\n```js\nvar Promise = require('bluebird');\nvar retry = require('bluebird-retry');\n\nvar count = 0;\nfunction myfunc() {\n    console.log('myfunc called ' + (++count) + ' times');\n    if (count < 3) {\n        return Promise.reject(new Error('fail the first two times'));\n    } else {\n        return Promise.resolve('succeed the third time');\n    }\n}\n\nretry(myfunc)\n.then(function(result) {\n    console.log(result);\n});\n```\n\nThis will display:\n\n```\nmyfunc called 1 times\nmyfunc called 2 times\nmyfunc called 3 times\nsucceed the third time\n```\n\nThe function is executed by `Promise.attempt`, so it can return a simple value or a\nPromise that resolves successfully to indicate success, or it can throw an Error\nor a rejected promise to indicate failure.\n\nNote that the rejection messages from the first two failed calls\nwere absorbed by `retry`.\n\n## Options\n\nThe maximum number of retries and controls for the interval\nbetween retries can be specified via the `options` parameter:\n\n* `interval` initial wait time between attempts in milliseconds (default 1000)\n* `backoff` if specified, increase interval by this factor between attempts\n* `max_interval` if specified, maximum amount that interval can increase to\n* `timeout` total time to wait for the operation to succeed in milliseconds\n* `max_tries` maximum number of attempts to try the operation (default 5)\n* `predicate` to be used as bluebird's [Filtered Catch](http://bluebirdjs.com/docs/api/catch.html#filtered-catch). `func` will be retried only if the predicate expectation is met, it will otherwise fail immediately.\n* `throw_original` to throw the last thrown error instance rather then a timeout error.\n* `context` if specified, is used as the `this` context when calling `func`\n* `args` if specified, is passed as arguments to `func`\n\nNote that `timeout` does not actually set a real timeout for the operation,\nbut actually computes a maximum number of attempts based on the interval\noptions. If both `timeout` and `max_tries` are specified, then whichever\nlimit comes first applies. If `max_tries` is set to `-1` and no `timeout` \nis specified, retry will be performed forever.\n\nFor example:\n\n```js\nfunction logFail() {\n    console.log(new Date().toISOString());\n    throw new Error('bail');\n}\n\nretry(logFail, { max_tries: 4, interval: 500 });\n```\nWill display:\n```\n2014-05-29T23:16:28.941Z\n2014-05-29T23:16:29.445Z\n2014-05-29T23:16:29.946Z\n2014-05-29T23:16:30.447Z\nError: operation timed out\n```\n\nAnd\n\n```js\nretry(logFail, { timeout: 10000, interval: 1000, backoff: 2 });\n```\nWill display:\n\n```\n2014-05-29T23:17:29.655Z\n2014-05-29T23:17:30.658Z\n2014-05-29T23:17:32.660Z\n2014-05-29T23:17:36.661Z\nError: operation timed out\n```\n\n## Stopping\n\nThe library also supports stopping the retry loop before the timeout occurs by throwing a new instance of `retry.StopError` from within the called function.\n\nFor example:\n\n```js\nvar retry = require('bluebird-retry');\nvar i = 0;\nvar err;\nvar swing = function() {\n    i++;\n    console.log('strike ' + i);\n    if (i == 3) {\n        throw new retry.StopError('yer out');\n    }\n    throw new Error('still up at bat');\n};\n\nretry(swing, {timeout: 10000})\n.caught(function(e) {\n    console.log(e.message)\n});\n```\n\nWill display:\n\n```\nstrike 1\nstrike 2\nstrike 3\nyer out\n```\n\nThe `StopError` constructor accepts one argument. If it is invoked with an instance of `Error`, then the promise is rejected with that error argument. Otherwise the promise is rejected with the `StopError` itself.\n","maintainers":[{"name":"arve.knudsen","email":"arve.knudsen@gmail.com"}],"time":{"modified":"2022-06-12T14:49:02.095Z","created":"2017-06-13T20:19:01.676Z","0.10.2":"2017-06-13T20:19:01.676Z"},"homepage":"https://github.com/aknuds1/bluebird-retry","keywords":["bluebird","promise","retry"],"repository":{"type":"git","url":"git+https://github.com/aknuds1/bluebird-retry.git"},"author":{"name":"Michael Demmer","email":"demmer@jut.io"},"bugs":{"url":"https://github.com/aknuds1/bluebird-retry/issues"},"license":"MIT","readmeFilename":"README.md"}