func RunWithResponse[T any]()

in retry/retry.go [61:94]


func RunWithResponse[T any](ctx context.Context, policy Policy, f func() (T, error)) (T, error) {
	var (
		res T
		err error
	)

	if f == nil {
		return res, fmt.Errorf("retry function cannot be nil")
	}

	for attempt := 0; attempt < policy.MaxAttempts; attempt++ {
		if res, err = f(); err == nil {
			return res, nil
		}

		if err != nil && !isRetriable(policy, err) {
			return res, fmt.Errorf("giving up, retry policy returned false on error: %+v", err)
		}

		logger.Debugf("Attempt %d failed with error %+v", attempt, err)

		// Return early, no need to wait if all retries have exhausted.
		if attempt+1 >= policy.MaxAttempts {
			return res, fmt.Errorf("exhausted all (%d) retries, last error: %+v", policy.MaxAttempts, err)
		}

		select {
		case <-ctx.Done():
			return res, ctx.Err()
		case <-time.After(backoff(attempt, policy)):
		}
	}
	return res, fmt.Errorf("num of retries set to 0, made no attempts to run")
}