Name: js-handler/node_modules/restify/node_modules/backoff/index.js
| 1: | /* |
| 2: | * Copyright (c) 2012 Mathieu Turcotte |
| 3: | * Licensed under the MIT license. |
| 4: | */ |
| 5: | |
| 6: | var Backoff = require('./lib/backoff'); |
| 7: | var ExponentialBackoffStrategy = require('./lib/strategy/exponential'); |
| 8: | var FibonacciBackoffStrategy = require('./lib/strategy/fibonacci'); |
| 9: | var FunctionCall = require('./lib/function_call.js'); |
| 10: | |
| 11: | module.exports.Backoff = Backoff; |
| 12: | module.exports.FunctionCall = FunctionCall; |
| 13: | module.exports.FibonacciStrategy = FibonacciBackoffStrategy; |
| 14: | module.exports.ExponentialStrategy = ExponentialBackoffStrategy; |
| 15: | |
| 16: | /** |
| 17: | * Constructs a Fibonacci backoff. |
| 18: | * @param options Fibonacci backoff strategy arguments. |
| 19: | * @return The fibonacci backoff. |
| 20: | * @see FibonacciBackoffStrategy |
| 21: | */ |
| 22: | module.exports.fibonacci = function(options) { |
| 23: | return new Backoff(new FibonacciBackoffStrategy(options)); |
| 24: | }; |
| 25: | |
| 26: | /** |
| 27: | * Constructs an exponential backoff. |
| 28: | * @param options Exponential strategy arguments. |
| 29: | * @return The exponential backoff. |
| 30: | * @see ExponentialBackoffStrategy |
| 31: | */ |
| 32: | module.exports.exponential = function(options) { |
| 33: | return new Backoff(new ExponentialBackoffStrategy(options)); |
| 34: | }; |
| 35: | |
| 36: | /** |
| 37: | * Constructs a FunctionCall for the given function and arguments. |
| 38: | * @param fn The function to wrap in a backoff handler. |
| 39: | * @param vargs The function's arguments (var args). |
| 40: | * @param callback The function's callback. |
| 41: | * @return The FunctionCall instance. |
| 42: | */ |
| 43: | module.exports.call = function(fn, vargs, callback) { |
| 44: | var args = Array.prototype.slice.call(arguments); |
| 45: | fn = args[0]; |
| 46: | vargs = args.slice(1, args.length - 1); |
| 47: | callback = args[args.length - 1]; |
| 48: | return new FunctionCall(fn, vargs, callback); |
| 49: | }; |
