linx-simulator2/node_modules/backoff/index.js

32 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-09-18 08:11:16 +00:00
// Copyright (c) 2012 Mathieu Turcotte
// Licensed under the MIT license.
var Backoff = require('./lib/backoff');
var ExponentialBackoffStrategy = require('./lib/strategy/exponential');
var FibonacciBackoffStrategy = require('./lib/strategy/fibonacci');
var FunctionCall = require('./lib/function_call.js');
module.exports.Backoff = Backoff;
module.exports.FunctionCall = FunctionCall;
module.exports.FibonacciStrategy = FibonacciBackoffStrategy;
module.exports.ExponentialStrategy = ExponentialBackoffStrategy;
// Constructs a Fibonacci backoff.
module.exports.fibonacci = function(options) {
return new Backoff(new FibonacciBackoffStrategy(options));
};
// Constructs an exponential backoff.
module.exports.exponential = function(options) {
return new Backoff(new ExponentialBackoffStrategy(options));
};
// Constructs a FunctionCall for the given function and arguments.
module.exports.call = function(fn, vargs, callback) {
var args = Array.prototype.slice.call(arguments);
fn = args[0];
vargs = args.slice(1, args.length - 1);
callback = args[args.length - 1];
return new FunctionCall(fn, vargs, callback);
};