@@ -136,38 +136,6 @@ func DoWithData[T any](retryableFunc RetryableFuncWithData[T], opts ...Option) (
136136 return emptyT , err
137137 }
138138
139- // Setting attempts to 0 means we'll retry until we succeed
140- var lastErr error
141- if config .attempts == 0 {
142- for {
143- t , err := retryableFunc ()
144- if err == nil {
145- return t , nil
146- }
147-
148- if ! IsRecoverable (err ) {
149- return emptyT , err
150- }
151-
152- if ! config .retryIf (err ) {
153- return emptyT , err
154- }
155-
156- lastErr = err
157-
158- config .onRetry (n , err )
159- n ++
160- select {
161- case <- config .timer .After (delay (config , n , err )):
162- case <- config .context .Done ():
163- if config .wrapContextErrorWithLastError {
164- return emptyT , Error {context .Cause (config .context ), lastErr }
165- }
166- return emptyT , context .Cause (config .context )
167- }
168- }
169- }
170-
171139 errorLog := Error {}
172140
173141 attemptsForError := make (map [error ]uint , len (config .attemptsForError ))
@@ -184,6 +152,10 @@ func DoWithData[T any](retryableFunc RetryableFuncWithData[T], opts ...Option) (
184152
185153 errorLog = append (errorLog , unpackUnrecoverable (err ))
186154
155+ if ! IsRecoverable (err ) {
156+ return emptyT , err
157+ }
158+
187159 if ! config .retryIf (err ) {
188160 break
189161 }
@@ -198,8 +170,9 @@ func DoWithData[T any](retryableFunc RetryableFuncWithData[T], opts ...Option) (
198170 }
199171 }
200172
173+ // Setting attempts to 0 means we'll retry until we succeed
201174 // if this is last attempt - don't wait
202- if n == config .attempts - 1 {
175+ if config . attempts != 0 && n == config .attempts - 1 {
203176 break
204177 }
205178 n ++
@@ -213,7 +186,6 @@ func DoWithData[T any](retryableFunc RetryableFuncWithData[T], opts ...Option) (
213186 return emptyT , append (errorLog , context .Cause (config .context ))
214187 }
215188
216- shouldRetry = shouldRetry && n < config .attempts
217189 }
218190
219191 if config .lastErrorOnly {
0 commit comments