1.0.1 • Published 10 years ago
retry-fn v1.0.1
retry-fn
A more functional retry function
Installation
npm install retry-fnExample
var retryFn = require('retry-fn')
var retry = retryFn.bind(null, {retries: 3, timeout: retryFn.fib(75)})
retry(unreliableFunction, function (err, result) {
// ...
})Reference
retry-fn exports a function that takes 3 arguments:
optional
Number||Object, number of times to retry or an options object. Defaults to {retries: 3, timeout: 0}.{retries: Number, timeout: Number||Function}:retriesnumber of times to retry before calling the callback with an errortimeouta function taking the retry count, returning the number of milliseconds before attempting again. If anything else is passed it will be wrapped in a function and return that value on each call. Eg. pass a Number for "equally" spaced retries.
Function to attempt. Expecting the format
function(callback) { /* ... */ }. If your function takes any other arguments, consider binding it or wrapping it. Seeexample/hyperquest.js- Callback which is called on success or when all retries have been exhausted.
Comes with three timeout functions builtin:
retry.fib(factor), returns a function for generating the Fibonacci sequence. Withfactor=100: 100, 100, 200, 300, 500, 800, 1300retry.leo(factor), returns a function for generating the Leonardo sequence. Withfactor=100: 100, 100, 200, 300, 500, 900, 1500retry.exp(factor), returns a function for generating a sequence according tofactor^n. Withfactor=25: 1, 25, 625, 15625