lib/utils.js
function waitForAvailable(host, port, options) {
  return co(function*() {
    options = Object.assign(
      {},
      {
        initialMS: 300,
        retryMS: 100,
        retryCount: 25
      },
      options
    );

    // Delay initial amount before attempting to connect
    yield delay(options.initialMS);

    // Try up to a certain number of times to connect
    for (var i = 0; i < options.retryCount; i++) {
      // Attempt to connect, returns true/false
      var available = yield checkAvailable(host, port);

      // If connected then return
      if (available) return;

      // Otherwise delay the retry amount and try again
      yield delay(options.retryMS);
    }

    // If this is reached then unable to connect
    throw new Error('Server is unavailable');
  });
}
function waitForAvailable(host, port, options) {
  return co(function*() {
    options = Object.assign(
      {},
      {
        initialMS: 300,
        retryMS: 100,
        retryCount: 25
      },
      options
    );

    // Delay initial amount before attempting to connect
    yield delay(options.initialMS);

    // Try up to a certain number of times to connect
    for (var i = 0; i < options.retryCount; i++) {
      // Attempt to connect, returns true/false
      var available = yield checkAvailable(host, port);

      // If connected then return
      if (available) return;

      // Otherwise delay the retry amount and try again
      yield delay(options.retryMS);
    }

    // If this is reached then unable to connect
    throw new Error('Server is unavailable');
  });
}
function waitForAvailable ( host , port , options ) { return co ( function * ( ) { options = Object . assign ( { } , { initialMS : 300 , retryMS : 100 , retryCount : 25 } , options ) ; // Delay initial amount before attempting to connect yield delay ( options . initialMS ) ; // Try up to a certain number of times to connect for ( var i = 0 ; i < options . retryCount ; i ++ ) { // Attempt to connect, returns true/false var available = yield checkAvailable ( host , port ) ; // If connected then return if ( available ) return ; // Otherwise delay the retry amount and try again yield delay ( options . retryMS ) ; } // If this is reached then unable to connect throw new Error ( 'Server is unavailable' ) ; } ) ; }
Waits for a provided address to actively listen for incoming connections on a given
port.

@param {string} host the host to connect to
@param {number} port the port to check for availability
@param {object} [options] optional settings
@param {number} [options.retryMS] the amount of time to wait between retry attempts in ms
@param {number} [options.initialMS] the amount of time to wait before first attempting in ms
@param {number} [options.retryCount] the number of times to attempt retry
Waits for a provided address to actively listen for incoming connections on a given port .