code: function(self, event) {
      return function(err) {
        var _self = this;
        count = count - 1;
  
        // Destroyed
        if (self.state === DESTROYED || self.state === UNREFERENCED) {
          return this.destroy({ force: true });
        }
  
        if (event === 'connect') {
          // Destroyed
          if (self.state === DESTROYED || self.state === UNREFERENCED) {
            return _self.destroy({ force: true });
          }
  
          // Update the state
          var result = self.s.replicaSetState.update(_self);
          // Update the state with the new server
          if (result) {
            // Primary lastIsMaster store it
            if (_self.lastIsMaster() && _self.lastIsMaster().ismaster) {
              self.ismaster = _self.lastIsMaster();
            }
  
            // Remove the handlers
            for (let i = 0; i < handlers.length; i++) {
              _self.removeAllListeners(handlers[i]);
            }
  
            // Add stable state handlers
            _self.on('error', handleEvent(self, 'error'));
            _self.on('close', handleEvent(self, 'close'));
            _self.on('timeout', handleEvent(self, 'timeout'));
            _self.on('parseError', handleEvent(self, 'parseError'));
  
            // Enalbe the monitoring of the new server
            monitorServer(_self.lastIsMaster().me, self, {});
  
            // Rexecute any stalled operation
            rexecuteOperations(self);
          } else {
            _self.destroy({ force: true });
          }
        } else if (event === 'error') {
          error = err;
        }
  
        // Rexecute any stalled operation
        rexecuteOperations(self);
  
        // Are we done finish up callback
        if (count === 0) {
          callback(error);
        }
      };
    }
docs: Handle events