From e9871ec4abf9b0fa4acc38082ff3f063548e442f Mon Sep 17 00:00:00 2001 From: Aman Shrivastava Date: Fri, 27 Sep 2024 12:11:36 +0530 Subject: [PATCH] Fix for #676 --- pkg/utils/utils.go | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 94c28ecc..064288d4 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -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 + } + } +} \ No newline at end of file