Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Aman Shrivastava committed Sep 27, 2024
1 parent 94d368e commit e9871ec
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,16 @@ func RetrieveValFromMap[K comparable, V any](m map[K]V, key K) V {
// PollUntil validates if a certain condition is met at defined poll intervals.
// If a timeout is reached, an associated error is returned to the caller.
// condition contains the use-case specific code that returns true when a certain condition is achieved.
func PollUntil(pollInterval, timeOut <-chan time.Time, condition func() (bool, error)) error {
for {
select {
case <-timeOut:
return fmt.Errorf("timed out while waiting for job to complete")
case <-pollInterval:
if done, err := condition(); err != nil {
return err
} else if done {
return nil
}
}
}
}
func PollUntil(pollInterval *time.Ticker, timeOut <-chan time.Time, condition func() (bool, error)) error {
for {
select {
case <-timeOut:
return fmt.Errorf("timed out while waiting for job to complete")
default:
if done, err := condition(); err != nil || done {
return err
}
<-pollInterval.C
}
}
}

0 comments on commit e9871ec

Please sign in to comment.