lib/watch.js
function Watch(consul, opts) {
  var self = this;

  events.EventEmitter.call(self);

  opts = utils.normalizeKeys(opts);

  var options = utils.normalizeKeys(opts.options || {});
  options = utils.defaults(options, consul._defaults);
  options.wait = options.wait || '30s';
  options.index = options.index || '0';

  if (typeof options.timeout !== 'string' && typeof options.timeout !== 'number') {
    var wait = utils.parseDuration(options.wait);
    // A small random amount of additional wait time is added to the supplied
    // maximum wait time to spread out the wake up time of any concurrent
    // requests. This adds up to wait / 16 additional time to the maximum duration.
    options.timeout = Math.ceil(wait + Math.max(wait * 0.1, 500));
  }

  var backoffFactor = 100;
  if (opts.hasOwnProperty('backofffactor') && typeof opts.backofffactor === 'number') {
    backoffFactor = opts.backofffactor;
  }
  var backoffMax = 30 * 1000;
  if (opts.hasOwnProperty('backoffmax') && typeof opts.backoffmax === 'number') {
    backoffMax = opts.backoffmax;
  }
  var maxAttempts = -1;
  if (opts.hasOwnProperty('maxattempts') && typeof opts.maxattempts === 'number') {
    maxAttempts = opts.maxattempts;
  }

  self._context = { consul: consul };
  self._options = options;
  self._attempts = 0;
  self._maxAttempts = maxAttempts;
  self._backoffMax = backoffMax;
  self._backoffFactor = backoffFactor;
  self._method = opts.method;

  if (typeof opts.method !== 'function') {
    throw errors.Validation('method required');
  }

  process.nextTick(function() { self._run(); });
}
function Watch(consul, opts) {
  var self = this;

  events.EventEmitter.call(self);

  opts = utils.normalizeKeys(opts);

  var options = utils.normalizeKeys(opts.options || {});
  options = utils.defaults(options, consul._defaults);
  options.wait = options.wait || '30s';
  options.index = options.index || '0';

  if (typeof options.timeout !== 'string' && typeof options.timeout !== 'number') {
    var wait = utils.parseDuration(options.wait);
    // A small random amount of additional wait time is added to the supplied
    // maximum wait time to spread out the wake up time of any concurrent
    // requests. This adds up to wait / 16 additional time to the maximum duration.
    options.timeout = Math.ceil(wait + Math.max(wait * 0.1, 500));
  }

  var backoffFactor = 100;
  if (opts.hasOwnProperty('backofffactor') && typeof opts.backofffactor === 'number') {
    backoffFactor = opts.backofffactor;
  }
  var backoffMax = 30 * 1000;
  if (opts.hasOwnProperty('backoffmax') && typeof opts.backoffmax === 'number') {
    backoffMax = opts.backoffmax;
  }
  var maxAttempts = -1;
  if (opts.hasOwnProperty('maxattempts') && typeof opts.maxattempts === 'number') {
    maxAttempts = opts.maxattempts;
  }

  self._context = { consul: consul };
  self._options = options;
  self._attempts = 0;
  self._maxAttempts = maxAttempts;
  self._backoffMax = backoffMax;
  self._backoffFactor = backoffFactor;
  self._method = opts.method;

  if (typeof opts.method !== 'function') {
    throw errors.Validation('method required');
  }

  process.nextTick(function() { self._run(); });
}
function Watch ( consul , opts ) { var self = this ; events . EventEmitter . call ( self ) ; opts = utils . normalizeKeys ( opts ) ; var options = utils . normalizeKeys ( opts . options || { } ) ; options = utils . defaults ( options , consul . _defaults ) ; options . wait = options . wait || '30s' ; options . index = options . index || '0' ; if ( typeof options . timeout !== 'string' && typeof options . timeout !== 'number' ) { var wait = utils . parseDuration ( options . wait ) ; // A small random amount of additional wait time is added to the supplied // maximum wait time to spread out the wake up time of any concurrent // requests. This adds up to wait / 16 additional time to the maximum duration. options . timeout = Math . ceil ( wait + Math . max ( wait * 0.1 , 500 ) ) ; } var backoffFactor = 100 ; if ( opts . hasOwnProperty ( 'backofffactor' ) && typeof opts . backofffactor === 'number' ) { backoffFactor = opts . backofffactor ; } var backoffMax = 30 * 1000 ; if ( opts . hasOwnProperty ( 'backoffmax' ) && typeof opts . backoffmax === 'number' ) { backoffMax = opts . backoffmax ; } var maxAttempts = - 1 ; if ( opts . hasOwnProperty ( 'maxattempts' ) && typeof opts . maxattempts === 'number' ) { maxAttempts = opts . maxattempts ; } self . _context = { consul : consul } ; self . _options = options ; self . _attempts = 0 ; self . _maxAttempts = maxAttempts ; self . _backoffMax = backoffMax ; self . _backoffFactor = backoffFactor ; self . _method = opts . method ; if ( typeof opts . method !== 'function' ) { throw errors . Validation ( 'method required' ) ; } process . nextTick ( function ( ) { self . _run ( ) ; } ) ; }
Initialize a new `Watch` instance.
Initialize a new Watch instance .