0.0.6 • Published 9 years ago

expb.js v0.0.6

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

expb.js NPM

Exponential backoff with time outs in 2^n ms durations.

Usage:

  • After importing the package, you can use these different types of functions:

Capped

function capped(maxTries, producer, callback);
Here the default error checker is by checking if the statusCode is in the OK range ie >= 200 && <= 299
function cappedCustom(maxTries, errChecker, producer, callback);
Just like the capped version but you can provide a custom errChecker
function cappedNet(maxTries, producer, callback);
Here the default error checker is by checking if the statusCode is in the OK range ie >= 200 && <= 299
function cappedDefault(maxTries, producer, callback);
Here the default error checker is by checking if the err is null

Uncapped

function uncapped(producer, callback);
Here the default max value for tries is Math.log2(MAX_INT) and the default error checker is a netChecker
function uncappedCustom(errChecker, producer, callback);
Just like the uncapped version but here you can provide a custom errChecker
function uncappedNet(producer, callback);
Here the default error checker is by checking if the statusCode is in the OK range ie >= 200 && <= 299
function uncappedDefault(maxTries, producer, callback);
Here the default error checker is by checking if the err is null

Sample usage:

const expb    = require('expb.js');
const request = require('request');

function statusCode(err, result) {
    if (err)
        return 500;
    if (!result)
        return 404;
    return 200;
};

function queryGithub(callback) {
    request.get('https://github.com/search?q=exponential', function(err, response, result) {
        var status = statusCode(err, result);
        callback(status, { response: response, result: result });
    });
};

function tryGithub() {
    var func = expb.capped(10, queryGithub, function(status, result) {
        console.log(status, result);
        process.exit(0);
    });

    func();
};

tryGithub();
0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago