lib/mongodb/mongodb-core/lib/connection/pool.js
function(_connection) {
    return function() {
      // Destroyed state return
      if (self.state === DESTROYED || self.state === DESTROYING) {
        // Remove the connection from the list
        removeConnection(self, _connection);
        return _connection.destroy();
      }

      // Destroy all event emitters
      handlers.forEach(function(e) {
        _connection.removeAllListeners(e);
      });

      // Add the final handlers
      _connection.once('close', connectionFailureHandler(self, 'close'));
      _connection.once('error', connectionFailureHandler(self, 'error'));
      _connection.once('timeout', connectionFailureHandler(self, 'timeout'));
      _connection.once('parseError', connectionFailureHandler(self, 'parseError'));

      // Signal
      reauthenticate(self, _connection, function(err) {
        if (self.state === DESTROYED || self.state === DESTROYING) {
          return _connection.destroy();
        }
        // Remove the connection from the connectingConnections list
        removeConnection(self, _connection);

        // Handle error
        if (err) {
          return _connection.destroy();
        }

        // If we are c at the moment
        // Do not automatially put in available connections
        // As we need to apply the credentials first
        if (self.authenticating) {
          self.nonAuthenticatedConnections.push(_connection);
        } else {
          // Push to available
          self.availableConnections.push(_connection);
          // Execute any work waiting
          _execute(self)();
        }
      });
    };
  }
function(_connection) {
    return function() {
      // Destroyed state return
      if (self.state === DESTROYED || self.state === DESTROYING) {
        // Remove the connection from the list
        removeConnection(self, _connection);
        return _connection.destroy();
      }

      // Destroy all event emitters
      handlers.forEach(function(e) {
        _connection.removeAllListeners(e);
      });

      // Add the final handlers
      _connection.once('close', connectionFailureHandler(self, 'close'));
      _connection.once('error', connectionFailureHandler(self, 'error'));
      _connection.once('timeout', connectionFailureHandler(self, 'timeout'));
      _connection.once('parseError', connectionFailureHandler(self, 'parseError'));

      // Signal
      reauthenticate(self, _connection, function(err) {
        if (self.state === DESTROYED || self.state === DESTROYING) {
          return _connection.destroy();
        }
        // Remove the connection from the connectingConnections list
        removeConnection(self, _connection);

        // Handle error
        if (err) {
          return _connection.destroy();
        }

        // If we are c at the moment
        // Do not automatially put in available connections
        // As we need to apply the credentials first
        if (self.authenticating) {
          self.nonAuthenticatedConnections.push(_connection);
        } else {
          // Push to available
          self.availableConnections.push(_connection);
          // Execute any work waiting
          _execute(self)();
        }
      });
    };
  }
function ( _connection ) { return function ( ) { // Destroyed state return if ( self . state === DESTROYED || self . state === DESTROYING ) { // Remove the connection from the list removeConnection ( self , _connection ) ; return _connection . destroy ( ) ; } // Destroy all event emitters handlers . forEach ( function ( e ) { _connection . removeAllListeners ( e ) ; } ) ; // Add the final handlers _connection . once ( 'close' , connectionFailureHandler ( self , 'close' ) ) ; _connection . once ( 'error' , connectionFailureHandler ( self , 'error' ) ) ; _connection . once ( 'timeout' , connectionFailureHandler ( self , 'timeout' ) ) ; _connection . once ( 'parseError' , connectionFailureHandler ( self , 'parseError' ) ) ; // Signal reauthenticate ( self , _connection , function ( err ) { if ( self . state === DESTROYED || self . state === DESTROYING ) { return _connection . destroy ( ) ; } // Remove the connection from the connectingConnections list removeConnection ( self , _connection ) ; // Handle error if ( err ) { return _connection . destroy ( ) ; } // If we are c at the moment // Do not automatially put in available connections // As we need to apply the credentials first if ( self . authenticating ) { self . nonAuthenticatedConnections . push ( _connection ) ; } else { // Push to available self . availableConnections . push ( _connection ) ; // Execute any work waiting _execute ( self ) ( ) ; } } ) ; } ; }
Handle successful connection
Handle successful connection