code: func waitForState(stateCheckFunc func() error) (time.Duration, error) {
  	timeout := defaultSleepTime
  	alarm := time.After(timeout)
  	ticker := time.Tick(250 * time.Millisecond)
  
  	for {
  		select {
  		case <-alarm:
  			return timeout, fmt.Errorf("Failed to fetch states within %v", timeout)
  		case <-ticker:
  			err := stateCheckFunc()
  			if err == nil {
  				return timeout, nil
  			}
  			log.Debugf("Retrying assertion of states. err: %v", err)
  		}
  	}
  }
docs: // waitForState is a generic helper for repeatedly checking the status.
  // It gets a generic function stateCheckFunc() to be checked, which returns
  // nil on success, error otherwise. In case of failure, waitForState
  // retries to run stateCheckFunc, once in 250 msec, up to defaultSleepTime.