func WaitFor(ctx context.Context, params WaitForParams, fn func() error) error {
	waiter := NewExpBackoff(params.InitialDelay, params.MaxDelay, params.JitterType)
	defer waiter.Reset()
	after := time.After(params.Timeout)
	var err error
	for {
		select {
		case <-waiter.Retry():
			if err = fn(); err != nil {
				if _, ok := err.(StopRetry); ok {
					return err
				}
				if params.Logger != nil {
					params.Logger.WithError(err).Warn("Waiter check did not succeed - waiting for next retry")
				}
				continue
			}
			return nil
		case <-after:
			if params.TimeoutError != nil {
				return params.TimeoutError
			}
			if err != nil {
				return errors.Wrap(err, TimeoutErr.Error())
			}
			return TimeoutErr
		case <-ctx.Done():
			return ctx.Err()
		}
	}
}
// WaitFor is a generic backoff waiter that takes a context, params, and a check function.
// It uses the check function to check the condition.  If there are no errors,
// the waiter is done.  If there are errors, backoff waiting is performed depending
// on the intial delay and max delay parameters.  When the Timeout is reached,
// the TimeoutError is returned.  If the check function returns a StopRetryErr,
// then the waiter immediately returns.
WaitFor is a generic backoff waiter that takes a context, params, and a check function.
It uses the check function to check the condition.  If there are no errors,
the waiter is done.  If there are errors, backoff waiting is performed depending
on the intial delay and max delay parameters.  When the Timeout is reached,
the TimeoutError is returned.  If the check function returns a StopRetryErr,
then the waiter immediately returns.
// WaitFor is a generic backoff waiter that takes a context params and a check function . // It uses the check function to check the condition . If there are no errors // the waiter is done . If there are errors backoff waiting is performed depending // on the intial delay and max delay parameters . When the Timeout is reached // the TimeoutError is returned . If the check function returns a StopRetryErr // then the waiter immediately returns .
func WaitFor(ctx context.Context, params WaitForParams, fn func() error) error {
	waiter := NewExpBackoff(params.InitialDelay, params.MaxDelay, params.JitterType)
	defer waiter.Reset()
	after := time.After(params.Timeout)
	var err error
	for {
		select {
		case <-waiter.Retry():
			if err = fn(); err != nil {
				if _, ok := err.(StopRetry); ok {
					return err
				}
				if params.Logger != nil {
					params.Logger.WithError(err).Warn("Waiter check did not succeed - waiting for next retry")
				}
				continue
			}
			return nil
		case <-after:
			if params.TimeoutError != nil {
				return params.TimeoutError
			}
			if err != nil {
				return errors.Wrap(err, TimeoutErr.Error())
			}
			return TimeoutErr
		case <-ctx.Done():
			return ctx.Err()
		}
	}
}
func WaitFor ( ctx context . Context , params WaitForParams , fn func ( ) error ) error { waiter := NewExpBackoff ( params . InitialDelay , params . MaxDelay , params . JitterType ) defer waiter . Reset ( ) after := time . After ( params . Timeout ) var err error for { select { case <- waiter . Retry ( ) : if err = fn ( ) ; err != nil { if _ , ok := err . ( StopRetry ) ; ok { return err } if params . Logger != nil { params . Logger . WithError ( err ) . Warn ( " " ) } continue } return nil case <- after : if params . TimeoutError != nil { return params . TimeoutError } if err != nil { return errors . Wrap ( err , TimeoutErr . Error ( ) ) } return TimeoutErr case <- ctx . Done ( ) : return ctx . Err ( ) } } }
WaitFor is a generic backoff waiter that takes a context, params, and a check function.
WaitFor is a generic backoff waiter that takes a context params and a check function .