code: func (c *cluster) listenForJoins() {
  	c.wg.Add(1)
  	go func() {
  		defer c.wg.Done()
  
  		// When a cluster starts, the state is STARTING.
  		// We first want to wait for at least one node to join.
  		// Then we want to clear out the joiningLeavingNodes queue (buffered channel).
  		// Then we want to set the cluster state to NORMAL and resume processing of joiningLeavingNodes events.
  		// We use a bool `setNormal` to indicate when at least one node has joined.
  		var setNormal bool
  
  		for {
  
  			// Handle all pending joins before changing state back to NORMAL.
  			select {
  			case nodeAction := <-c.joiningLeavingNodes:
  				err := c.handleNodeAction(nodeAction)
  				if err != nil {
  					c.logger.Printf("handleNodeAction error: err=%s", err)
  					continue
  				}
  				setNormal = true
  				continue
  			default:
  			}
  
  			// Only change state to NORMAL if we have successfully added at least one host.
  			if setNormal {
  				// Put the cluster back to state NORMAL and broadcast.
  				if err := c.setStateAndBroadcast(ClusterStateNormal); err != nil {
  					c.logger.Printf("setStateAndBroadcast error: err=%s", err)
  				}
  			}
  
  			// Wait for a joining host or a close.
  			select {
  			case <-c.closing:
  				return
  			case nodeAction := <-c.joiningLeavingNodes:
  				err := c.handleNodeAction(nodeAction)
  				if err != nil {
  					c.logger.Printf("handleNodeAction error: err=%s", err)
  					continue
  				}
  				setNormal = true
  				continue
  			}
  		}
  	}()
  }
docs: // listenForJoins handles cluster-resize events.