Hi Andrew,

thanks for sharing, ``oibackoff`` could be useful for ``filewalker``[1]

I miss one thing: Infinite retries (maxTries: -1). This would require
a maxDelay option.

[1] https://github.com/oleics/node-filewalker

On Sun, Jun 3, 2012 at 3:17 AM, Andrew Chilton <[email protected]> wrote:
> Hi everyone,
>
> In this world of networked systems, we need things to be nice to each
> other. We also need to be nice to our own system. Hence, instead of
> incessantly asking something else for info (be it the filesystem, DNS,
> a website or a web service) we need to be kind - hence we need to
> backoff. Introducing Oi! Backoff - a flow control function for
> incremental backoff.
>
> * npm install oibackoff
> * https://github.com/appsattic/oibackoff/
> * http://search.npmjs.org/#/oibackoff
>
> It's ideal for networked things such as DNS, fetching a page, send a
> message to something else, calling an operation on a web service (AWS,
> RackspaceCloud, etc) and many other uses.
>
> As an example, let's say you want to do a DNS lookup but you need it
> to retry a few times if it fails:
>
>    var backoff = require('oibackoff').backoff({
>        algorithm  : 'exponential',
>        delayRatio : 0.2,
>        maxTries   : 5,
>    });
>
>    // called on 0.2, 0.4, 0.8 and 1.6s (until it succeeds or fails 5 times)
>    backoff(dns.resolve, 'chilts.org', function(err, addresses, priorErrors) {
>        if (err) {
>            // do something to recover from this error
>            return;
>        }
>
>        console.log(addresses);
>    });
>
> As you can see the interface is simple and familiar to the regular
> fn(err, data) callback pattern, but with an extra priorErrors array
> for previous errors. 'err' is the last error seen if all attempts
> fail.
>
> There are three backoff algorithms: linear (1, 2, 3, 4, 5),
> exponential (1, 2, 4, 8, 16) and fibonacci ;) (1, 1, 2, 3, 5, 8). Each
> can use a ratio to use subsecond (or multi second) precision.
>
> You can also specify the max number of tries before failing. All
> failures are passed to your callback as a list in priorErrors. And
> finally, you can set a maxDelay time despite maxTries and your chosen
> algorithm.
>
> Note: at the moment this works with the standard node callback
> signature such as fn(err, data). e.g. fs.stat, dns.resolve. If you
> need to use it on an object's function, then you'll need to create a
> fn(err, data) function yourself which does what you need it to do. :)
>
> Have fun,
> Andy
>
> --
> Andrew Chilton
> e: [email protected]
> w: http://appsattic.com/
> t: https://twitter.com/andychilton
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines: 
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en



-- 
Oliver Leics @ G+
https://plus.google.com/112912441146721682527

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to