code: func (ed *Dispatcher) HandleConnectEvent(e esdispatcher.Event) {
  	evt := e.(*ConnectEvent)
  
  	if ed.connection != nil {
  		// Already connected. No error.
  		evt.ErrCh <- nil
  		return
  	}
  
  	eventch, err := ed.EventCh()
  	if err != nil {
  		evt.ErrCh <- err
  		return
  	}
  
  	peers, err := ed.discoveryService.GetPeers()
  	if err != nil {
  		evt.ErrCh <- err
  		return
  	}
  
  	if len(peers) == 0 {
  		evt.ErrCh <- errors.New("no peers to connect to")
  		return
  	}
  
  	peer, err := ed.peerResolver.Resolve(peers)
  	if err != nil {
  		evt.ErrCh <- err
  		return
  	}
  
  	conn, err := ed.connectionProvider(ed.context, ed.chConfig, peer)
  	if err != nil {
  		logger.Warnf("error creating connection: %s", err)
  		evt.ErrCh <- errors.WithMessagef(err, "could not create client conn")
  		return
  	}
  
  	ed.connection = conn
  	ed.setConnectedPeer(peer)
  
  	go ed.connection.Receive(eventch)
  
  	evt.ErrCh <- nil
  }
docs: // HandleConnectEvent initiates a connection to the event server