Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/avast/retry-go/v4

go 1.18
go 1.20

require github.com/stretchr/testify v1.10.0

Expand Down
10 changes: 5 additions & 5 deletions retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func DoWithData[T any](retryableFunc RetryableFuncWithData[T], opts ...Option) (
opt(config)
}

if err := config.context.Err(); err != nil {
if err := context.Cause(config.context); err != nil {
return emptyT, err
}

Expand Down Expand Up @@ -161,9 +161,9 @@ func DoWithData[T any](retryableFunc RetryableFuncWithData[T], opts ...Option) (
case <-config.timer.After(delay(config, n, err)):
case <-config.context.Done():
if config.wrapContextErrorWithLastError {
return emptyT, Error{config.context.Err(), lastErr}
return emptyT, Error{context.Cause(config.context), lastErr}
}
return emptyT, config.context.Err()
return emptyT, context.Cause(config.context)
}
}
}
Expand Down Expand Up @@ -207,10 +207,10 @@ func DoWithData[T any](retryableFunc RetryableFuncWithData[T], opts ...Option) (
case <-config.timer.After(delay(config, n, err)):
case <-config.context.Done():
if config.lastErrorOnly {
return emptyT, config.context.Err()
return emptyT, context.Cause(config.context)
}

return emptyT, append(errorLog, config.context.Err())
return emptyT, append(errorLog, context.Cause(config.context))
}

shouldRetry = shouldRetry && n < config.attempts
Expand Down