Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mgyucht committed Dec 23, 2024
1 parent b947958 commit ab7ed04
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions httpclient/retries.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
func makeRetrier[T any](c ClientConfig) retries.Retrier[T] {
return retries.New[T](
retries.WithTimeout(c.RetryTimeout),
retries.WithRetryFunc(retries.DefaultShouldRetry),
retries.WithBackoffFunc(c.RetryBackoff),
)
}
6 changes: 3 additions & 3 deletions retries/retries.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (r Retrier[T]) Run(ctx context.Context, fn func(context.Context) (*T, error
}
}

func shouldRetry(err error) bool {
func DefaultShouldRetry(err error) bool {
if err == nil {
return false
}
Expand All @@ -252,7 +252,7 @@ func shouldRetry(err error) bool {
}

func Wait(ctx context.Context, timeout time.Duration, fn func() *Err) error {
return New[struct{}](WithTimeout(timeout), WithRetryFunc(shouldRetry)).Wait(ctx, func(_ context.Context) error {
return New[struct{}](WithTimeout(timeout), WithRetryFunc(DefaultShouldRetry)).Wait(ctx, func(_ context.Context) error {
err := fn()
if err != nil {
return err
Expand All @@ -262,7 +262,7 @@ func Wait(ctx context.Context, timeout time.Duration, fn func() *Err) error {
}

func Poll[T any](ctx context.Context, timeout time.Duration, fn func() (*T, *Err)) (*T, error) {
return New[T](WithTimeout(timeout), WithRetryFunc(shouldRetry)).Run(ctx, func(_ context.Context) (*T, error) {
return New[T](WithTimeout(timeout), WithRetryFunc(DefaultShouldRetry)).Run(ctx, func(_ context.Context) (*T, error) {
res, err := fn()
if err != nil {
return res, err
Expand Down

0 comments on commit ab7ed04

Please sign in to comment.