Skip to content

Commit

Permalink
Update util.go
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentYe123 committed May 19, 2023
1 parent 4ae4cc5 commit 64ab038
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (
"google.golang.org/grpc/grpclog"
)

func until(f func(), period time.Duration, stopCh <-chan struct{}) {
func until(f func(), initialPeriod, maxPeriod time.Duration, stopCh <-chan struct{}) {
select {
case <-stopCh:
return
default:
}
period := initialPeriod
for {
func() {
defer handleCrash()
Expand All @@ -22,6 +23,11 @@ func until(f func(), period time.Duration, stopCh <-chan struct{}) {
case <-stopCh:
return
case <-time.After(period):
if period*2 <= maxPeriod {
period *= 2
} else {
period = initialPeriod
}
}
}
}
Expand Down

0 comments on commit 64ab038

Please sign in to comment.