Skip to content

Commit cbf4dbf

Browse files
authored
Merge pull request avast#117 from NivKeidan/support-context-cancel-cause
support context cancel cause
2 parents 93932f8 + 912b0c5 commit cbf4dbf

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/avast/retry-go/v4
22

3-
go 1.18
3+
go 1.20
44

55
require github.com/stretchr/testify v1.10.0
66

retry.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func DoWithData[T any](retryableFunc RetryableFuncWithData[T], opts ...Option) (
132132
opt(config)
133133
}
134134

135-
if err := config.context.Err(); err != nil {
135+
if err := context.Cause(config.context); err != nil {
136136
return emptyT, err
137137
}
138138

@@ -161,9 +161,9 @@ func DoWithData[T any](retryableFunc RetryableFuncWithData[T], opts ...Option) (
161161
case <-config.timer.After(delay(config, n, err)):
162162
case <-config.context.Done():
163163
if config.wrapContextErrorWithLastError {
164-
return emptyT, Error{config.context.Err(), lastErr}
164+
return emptyT, Error{context.Cause(config.context), lastErr}
165165
}
166-
return emptyT, config.context.Err()
166+
return emptyT, context.Cause(config.context)
167167
}
168168
}
169169
}
@@ -207,10 +207,10 @@ func DoWithData[T any](retryableFunc RetryableFuncWithData[T], opts ...Option) (
207207
case <-config.timer.After(delay(config, n, err)):
208208
case <-config.context.Done():
209209
if config.lastErrorOnly {
210-
return emptyT, config.context.Err()
210+
return emptyT, context.Cause(config.context)
211211
}
212212

213-
return emptyT, append(errorLog, config.context.Err())
213+
return emptyT, append(errorLog, context.Cause(config.context))
214214
}
215215

216216
shouldRetry = shouldRetry && n < config.attempts

0 commit comments

Comments
 (0)