code: func (m *Main) waitForLeader(timeout time.Duration) error {
  	// Ignore leadership if we are a proxy.
  	if m.store == nil {
  		return nil
  	}
  	var timeoutCh <-chan time.Time
  	if timeout != IndefiniteTimeout {
  		timeoutCh = time.After(timeout)
  	}
  	for {
  		select {
  		case <-timeoutCh:
  			return errors.New("timed out waiting for leader")
  		case <-time.After(100 * time.Millisecond):
  			if leader := m.store.Leader(); leader != "" {
  				return nil
  			}
  		}
  	}
  }
docs: // waitForLeader polls the store until a leader is found or a timeout occurs.
  // If timeout is -1 then wait indefinitely