code: func (n *Node) waitRole(ctx context.Context, role string) error {
  	n.roleCond.L.Lock()
  	if role == n.role {
  		n.roleCond.L.Unlock()
  		return nil
  	}
  	finishCh := make(chan struct{})
  	defer close(finishCh)
  	go func() {
  		select {
  		case <-finishCh:
  		case <-ctx.Done():
  			// call broadcast to shutdown this function
  			n.roleCond.Broadcast()
  		}
  	}()
  	defer n.roleCond.L.Unlock()
  	for role != n.role {
  		n.roleCond.Wait()
  		select {
  		case <-ctx.Done():
  			return ctx.Err()
  		default:
  		}
  	}
  
  	return nil
  }
docs: // waitRole takes a context and a role. it the blocks until the context is
  // canceled or the node's role updates to the provided role. returns nil when
  // the node has acquired the provided role, or ctx.Err() if the context is
  // canceled