mqlight.js
function(error) {
          logger.entry('Client._tryService.tryNextService', _id);

          if (serviceList.length === 1) {
            // We've tried all services without success. Pause for a while
            // before trying again
            logger.log('data', _id, 'End of service list');

            client._setState(STATE_RETRYING);
            var retry = function() {
              logger.entryLevel('entry_often', 'Client._tryService.retry', _id);
              if (!client.isStopped()) {
                process.nextTick(function() {
                  client._performConnect(false, true);
                });
              }
              logger.exitLevel('exit_often', 'Client._tryService.retry',
                               _id, null);
            };

            client._retryCount++;
            var retryCap = 60000;
            // Limit to the power of 8 as anything above this will put the
            // interval higher than the cap straight away.
            var exponent = (client._retryCount <= 8) ? client._retryCount : 8;
            var upperBound = Math.pow(2, exponent);
            var lowerBound = 0.75 * upperBound;
            var jitter = Math.random() * (0.25 * upperBound);
            var interval = Math.min(retryCap, (lowerBound + jitter) * 1000);
            // times by CONNECT_RETRY_INTERVAL for unittest purposes
            interval = Math.round(interval) * CONNECT_RETRY_INTERVAL;
            logger.log('data', _id, 'trying to connect again ' +
                       'after ' + (interval / 1000) + ' seconds');
            setTimeout(retry, interval);
            if (error) {
              setImmediate(function() {
                logger.log('emit', _id, 'error', error);
                client.emit('error', error);
              });
            }
          } else {
            // Try the next service in the list
            logger.log('data', _id, 'Trying next service');
            client._tryService(serviceList.slice(1));
          }

          logger.exit('Client._tryService.tryNextService', _id, null);
        }
function(error) {
          logger.entry('Client._tryService.tryNextService', _id);

          if (serviceList.length === 1) {
            // We've tried all services without success. Pause for a while
            // before trying again
            logger.log('data', _id, 'End of service list');

            client._setState(STATE_RETRYING);
            var retry = function() {
              logger.entryLevel('entry_often', 'Client._tryService.retry', _id);
              if (!client.isStopped()) {
                process.nextTick(function() {
                  client._performConnect(false, true);
                });
              }
              logger.exitLevel('exit_often', 'Client._tryService.retry',
                               _id, null);
            };

            client._retryCount++;
            var retryCap = 60000;
            // Limit to the power of 8 as anything above this will put the
            // interval higher than the cap straight away.
            var exponent = (client._retryCount <= 8) ? client._retryCount : 8;
            var upperBound = Math.pow(2, exponent);
            var lowerBound = 0.75 * upperBound;
            var jitter = Math.random() * (0.25 * upperBound);
            var interval = Math.min(retryCap, (lowerBound + jitter) * 1000);
            // times by CONNECT_RETRY_INTERVAL for unittest purposes
            interval = Math.round(interval) * CONNECT_RETRY_INTERVAL;
            logger.log('data', _id, 'trying to connect again ' +
                       'after ' + (interval / 1000) + ' seconds');
            setTimeout(retry, interval);
            if (error) {
              setImmediate(function() {
                logger.log('emit', _id, 'error', error);
                client.emit('error', error);
              });
            }
          } else {
            // Try the next service in the list
            logger.log('data', _id, 'Trying next service');
            client._tryService(serviceList.slice(1));
          }

          logger.exit('Client._tryService.tryNextService', _id, null);
        }
function ( error ) { logger . entry ( 'Client._tryService.tryNextService' , _id ) ; if ( serviceList . length === 1 ) { // We've tried all services without success. Pause for a while // before trying again logger . log ( 'data' , _id , 'End of service list' ) ; client . _setState ( STATE_RETRYING ) ; var retry = function ( ) { logger . entryLevel ( 'entry_often' , 'Client._tryService.retry' , _id ) ; if ( ! client . isStopped ( ) ) { process . nextTick ( function ( ) { client . _performConnect ( false , true ) ; } ) ; } logger . exitLevel ( 'exit_often' , 'Client._tryService.retry' , _id , null ) ; } ; client . _retryCount ++ ; var retryCap = 60000 ; // Limit to the power of 8 as anything above this will put the // interval higher than the cap straight away. var exponent = ( client . _retryCount <= 8 ) ? client . _retryCount : 8 ; var upperBound = Math . pow ( 2 , exponent ) ; var lowerBound = 0.75 * upperBound ; var jitter = Math . random ( ) * ( 0.25 * upperBound ) ; var interval = Math . min ( retryCap , ( lowerBound + jitter ) * 1000 ) ; // times by CONNECT_RETRY_INTERVAL for unittest purposes interval = Math . round ( interval ) * CONNECT_RETRY_INTERVAL ; logger . log ( 'data' , _id , 'trying to connect again ' + 'after ' + ( interval / 1000 ) + ' seconds' ) ; setTimeout ( retry , interval ) ; if ( error ) { setImmediate ( function ( ) { logger . log ( 'emit' , _id , 'error' , error ) ; client . emit ( 'error' , error ) ; } ) ; } } else { // Try the next service in the list logger . log ( 'data' , _id , 'Trying next service' ) ; client . _tryService ( serviceList . slice ( 1 ) ) ; } logger . exit ( 'Client._tryService.tryNextService' , _id , null ) ; }
Try and connect to the next service in the list, or retry from the beginning if we've run out of services.
Try and connect to the next service in the list or retry from the beginning if we ve run out of services .