Add wait.PollImmediateUntil
This commit is contained in:
@@ -284,12 +284,32 @@ func PollImmediateInfinite(interval time.Duration, condition ConditionFunc) erro
|
|||||||
// PollUntil tries a condition func until it returns true, an error or stopCh is
|
// PollUntil tries a condition func until it returns true, an error or stopCh is
|
||||||
// closed.
|
// closed.
|
||||||
//
|
//
|
||||||
// PolUntil always waits interval before the first run of 'condition'.
|
// PollUntil always waits interval before the first run of 'condition'.
|
||||||
// 'condition' will always be invoked at least once.
|
// 'condition' will always be invoked at least once.
|
||||||
func PollUntil(interval time.Duration, condition ConditionFunc, stopCh <-chan struct{}) error {
|
func PollUntil(interval time.Duration, condition ConditionFunc, stopCh <-chan struct{}) error {
|
||||||
return WaitFor(poller(interval, 0), condition, stopCh)
|
return WaitFor(poller(interval, 0), condition, stopCh)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PollImmediateUntil tries a condition func until it returns true, an error or stopCh is closed.
|
||||||
|
//
|
||||||
|
// PollImmediateUntil runs the 'condition' before waiting for the interval.
|
||||||
|
// 'condition' will always be invoked at least once.
|
||||||
|
func PollImmediateUntil(interval time.Duration, condition ConditionFunc, stopCh <-chan struct{}) error {
|
||||||
|
done, err := condition()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if done {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case <-stopCh:
|
||||||
|
return ErrWaitTimeout
|
||||||
|
default:
|
||||||
|
return PollUntil(interval, condition, stopCh)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// WaitFunc creates a channel that receives an item every time a test
|
// WaitFunc creates a channel that receives an item every time a test
|
||||||
// should be executed and is closed when the last test should be invoked.
|
// should be executed and is closed when the last test should be invoked.
|
||||||
type WaitFunc func(done <-chan struct{}) <-chan struct{}
|
type WaitFunc func(done <-chan struct{}) <-chan struct{}
|
||||||
|
|||||||
Reference in New Issue
Block a user