阅读 k8s 源码过程发现总会有 wait.Poll(param)
之类的函数调用,因此参考 pkg.go.dev 与 github.com 对 wait
包中提供的常用函数做了汇总,提升阅读效率。
1
| type ConditionFunc func() (done bool, err error)
|
1 2 3 4 5 6 7 8
| func Poll(interval time.Duration, condition ConditionFunc) error
func PollInfinite(interval time.Duration, condition ConditionFunc) error
func PollUntil(interval time.Duration, condition ConditionFunc, stopCh <-chan struct{}) error
|
1 2 3 4 5 6 7 8
| func PollImmediate(interval, timeout time.Duration, condition ConditionFunc) error
func PollImmediateInfinite(interval time.Duration, condition ConditionFunc) error
func PollImmediateUntil(interval time.Duration, condition ConditionFunc, stopCh <-chan struct{}) error
|
1 2 3 4 5 6 7 8 9 10
|
func JitterUntil(f func(), period time.Duration, jitterFactor float64, sliding bool, stopCh <-chan struct{})
func Until(f func(), period time.Duration, stopCh <-chan struct{})
func NonSlidingUntil(f func(), period time.Duration, stopCh <-chan struct{})
|
以上函数均支持传入ctx context.Context
参数,形成带上下文的函数.
如 func PollImmediateWithContext(ctx context.Context, interval, timeout time.Duration, condition ConditionWithContextFunc) error
等
参考