<commit_before>#!/usr/bin/env node

var assert = require('assert');

var backoff = require('../index.js');

// Contruct a function which will fail on its first two calls.
var foo = (function() {
    var args = [[new Error('1')], [new Error('2')], [null, 'ok']];

    return function(callback) {
        callback.apply(null, args.shift());
    };
}());

// Wrap the unreliable function in a backoff handler.
var fooBackoff = backoff.wrap(foo, {
    randomizationFactor: 0.3,
    initialDelay: 5,
    maxDelay: 500
}, backoff.ExponentialStrategy, 10);

// Call the wrapped function which should now succeed.
fooBackoff(function(err, result, results) {
    assert.equal(results.length, 3);
    assert.equal(result, 'ok');
    assert.ok(!err);
});
<commit_msg>Clean backoff.wrap example.<commit_after>#!/usr/bin/env node

var assert = require('assert');

var backoff = require('../index.js');

// Contruct a function which will fail on its first two calls.
var foo = (function() {
    var args = [[new Error('1'), null],
                [new Error('2'), null],
                [null, 'ok']];

    return function(callback) {
        callback.apply(null, args.shift());
    };
}());

// Wrap the unreliable function in a backoff handler.
var fooBackoff = backoff.wrap(foo);

// Call the wrapped function which should now succeed.
fooBackoff(function(err, result, results) {
    assert.equal(results.length, 3);
    assert.equal(result, 'ok');
    assert.ok(!err);
});

{'fraction_non_alphanumeric': 0.16267942583732056, 'fraction_numerical': 0.009569377990430622, 'mean_word_length': 3.370149253731343, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6859679', 'n_tokens_mistral': 470, 'n_tokens_neox': 448, 'n_words': 134}