Skip to content

Commit

Permalink
use channel
Browse files Browse the repository at this point in the history
  • Loading branch information
chirauki committed May 30, 2024
1 parent 4bbc6f5 commit 0253ab7
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions pkg/helpers/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,24 @@ func (r *RetryWindow) Do(action func(attempt int, successes int) bool) RetryResu
successCount := 0
// run a while true loop, exiting when the timeout expires
for {
attempt++
if action(attempt, successCount) {
successCount++
if successCount >= r.ConsecutiveSuccesses {
success <- struct{}{}
return
}
} else {
successCount = 0
}
if r.Context != nil {
if err := r.Context.Err(); err != nil {
if err == context.Canceled || err == context.DeadlineExceeded {
failure <- struct{}{}
select {
case <-r.Context.Done():
failure <- struct{}{}
return
default:
attempt++
if action(attempt, successCount) {
successCount++
if successCount >= r.ConsecutiveSuccesses {
success <- struct{}{}
return
}
} else {
successCount = 0
}
time.Sleep(r.Interval)
}
time.Sleep(r.Interval)
}

}()

select {
Expand Down

0 comments on commit 0253ab7

Please sign in to comment.