{"_id":"stubbornizeasync","_rev":"5-5e97be0cb4db8d3f2fa127d9582c96ca","name":"stubbornizeasync","description":"Helper for making an async function stubborn (retry the operation on failure)","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"stubbornizeasync","version":"0.1.0","description":"Helper for making an async function stubborn (retry the operation on failure)","main":"lib/stubbornizeAsync.js","directories":{"test":"test"},"dependencies":{},"devDependencies":{"mocha":"=1.7.3","expect.js":"=0.2.0"},"scripts":{"prepublish":"mocha","test":"mocha"},"repository":{"type":"git","url":"git://github.com/papandreou/stubbornizeasync.git"},"keywords":["stubborn","error","failure","tolerance","async"],"author":{"name":"Andreas Lind Petersen","email":"andreas@one.com"},"license":"BSD","readme":"stubbornizeasync\n================\n\nCreate a \"stubborn\" version of an asynchronous function so that the\noperation is retried a configurable number of times in case the\noriginal function returns an error.\n\n```javascript\nvar stubbornizeAsync = require('stubbornizeasync');\n\n// This function will fail ~10% of the time\nfunction myFlakyFunction(cb) {\n    setTimeout(function () {\n        if (Math.random() > .9) {\n            cb(new Error(\"whoops\"));\n        } else {\n            cb();\n        }\n    }, 10);\n}\n\n// This function will fail ~1% of the time:\nvar stubbornFunction = stubbornizeAsync(myFlakyFunction, {numRetries: 1});\n\n// This function will fail ~0.01% of the time:\nvar evenMoreStubbornFunction = stubbornizeAsync(myFlakyFunction, {numRetries: 3});\n\nevenMoreStubbornFunction(function (err) {\n    if (err) {\n        throw err;\n    } else {\n        // Yay!\n    }\n});\n```\n\nBy default the stubbornized function retries the original function 3\ntimes (so it's run a maximum of 4 times), and it waits 250\nmilliseconds between the attempts. These parameters can be adjusted by\nproviding an options object as the second parameter to\n`stubbornizeAsync`:\n\n```javascript\nvar veryStubbornAndVeryPatientFunction = stubbornizeAsync(myFlakyFunction, {numRetries: 10, delayMsec: 10000});\n```\n\nInstallation\n------------\n\nMake sure you have node.js and npm installed, then run:\n\n    npm install stubbornizeasync\n\nLicense\n-------\n\n3-clause BSD license -- see the `LICENSE` file for details.\n","readmeFilename":"README.md","_id":"stubbornizeasync@0.1.0","dist":{"shasum":"712b60bb259959eb7577e0a30564150df52c60c1","tarball":"https://registry.npmjs.org/stubbornizeasync/-/stubbornizeasync-0.1.0.tgz","integrity":"sha512-vSRftovnOlKgbcTiQY2UNP1IBsLWCQjkfN0P4Xy6mTsy8eupH6IwFwpXbYopPnuhzuj3AIQVpX1Vl9nDFqGotA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGXO4a4IHqJHgW2CxSIZro139SSbE4jFemuke3DIHg5NAiAYLMh7aB6NVauC7DJqK5Vt4iNqnDqIlMsWDnN95mIkuA=="}]},"_from":".","_npmVersion":"1.2.11","_npmUser":{"name":"papandreou","email":"andreas@one.com"},"maintainers":[{"name":"papandreou","email":"andreas@one.com"}]}},"readme":"stubbornizeasync\n================\n\nCreate a \"stubborn\" version of an asynchronous function so that the\noperation is retried a configurable number of times in case the\noriginal function returns an error.\n\n```javascript\nvar stubbornizeAsync = require('stubbornizeasync');\n\n// This function will fail ~10% of the time\nfunction myFlakyFunction(cb) {\n    setTimeout(function () {\n        if (Math.random() > .9) {\n            cb(new Error(\"whoops\"));\n        } else {\n            cb();\n        }\n    }, 10);\n}\n\n// This function will fail ~1% of the time:\nvar stubbornFunction = stubbornizeAsync(myFlakyFunction, {numRetries: 1});\n\n// This function will fail ~0.01% of the time:\nvar evenMoreStubbornFunction = stubbornizeAsync(myFlakyFunction, {numRetries: 3});\n\nevenMoreStubbornFunction(function (err) {\n    if (err) {\n        throw err;\n    } else {\n        // Yay!\n    }\n});\n```\n\nBy default the stubbornized function retries the original function 3\ntimes (so it's run a maximum of 4 times), and it waits 250\nmilliseconds between the attempts. These parameters can be adjusted by\nproviding an options object as the second parameter to\n`stubbornizeAsync`:\n\n```javascript\nvar veryStubbornAndVeryPatientFunction = stubbornizeAsync(myFlakyFunction, {numRetries: 10, delayMsec: 10000});\n```\n\nInstallation\n------------\n\nMake sure you have node.js and npm installed, then run:\n\n    npm install stubbornizeasync\n\nLicense\n-------\n\n3-clause BSD license -- see the `LICENSE` file for details.\n","maintainers":[{"name":"papandreou","email":"andreas@one.com"}],"time":{"modified":"2022-06-27T01:24:33.752Z","created":"2013-05-03T14:11:01.189Z","0.1.0":"2013-05-03T14:11:03.180Z"},"author":{"name":"Andreas Lind Petersen","email":"andreas@one.com"},"repository":{"type":"git","url":"git://github.com/papandreou/stubbornizeasync.git"}}