kubernetes: k8s.io/kubernetes/pkg/util/async Index | Files

package async

import "k8s.io/kubernetes/pkg/util/async"


Package Files

bounded_frequency_runner.go runner.go

type BoundedFrequencyRunner Uses

type BoundedFrequencyRunner struct {
    // contains filtered or unexported fields

BoundedFrequencyRunner manages runs of a user-provided function. See NewBoundedFrequencyRunner for examples.

func NewBoundedFrequencyRunner Uses

func NewBoundedFrequencyRunner(name string, fn func(), minInterval, maxInterval time.Duration, burstRuns int) *BoundedFrequencyRunner

NewBoundedFrequencyRunner creates a new BoundedFrequencyRunner instance, which will manage runs of the specified function.

All runs will be async to the caller of BoundedFrequencyRunner.Run, but multiple runs are serialized. If the function needs to hold locks, it must take them internally.

Runs of the function will have at least minInterval between them (from completion to next start), except that up to bursts may be allowed. Burst runs are "accumulated" over time, one per minInterval up to burstRuns total. This can be used, for example, to mitigate the impact of expensive operations being called in response to user-initiated operations. Run requests that would violate the minInterval are coallesced and run at the next opportunity.

The function will be run at least once per maxInterval. For example, this can force periodic refreshes of state in the absence of anyone calling Run.


NewBoundedFrequencyRunner("name", fn, time.Second, 5*time.Second, 1) - fn will have at least 1 second between runs - fn will have no more than 5 seconds between runs

NewBoundedFrequencyRunner("name", fn, 3*time.Second, 10*time.Second, 3) - fn will have at least 3 seconds between runs, with up to 3 burst runs - fn will have no more than 10 seconds between runs

The maxInterval must be greater than or equal to the minInterval, If the caller passes a maxInterval less than minInterval, this function will panic.

func (*BoundedFrequencyRunner) Loop Uses

func (bfr *BoundedFrequencyRunner) Loop(stop <-chan struct{})

Loop handles the periodic timer and run requests. This is expected to be called as a goroutine.

func (*BoundedFrequencyRunner) Run Uses

func (bfr *BoundedFrequencyRunner) Run()

Run the function as soon as possible. If this is called while Loop is not running, the call may be deferred indefinitely. If there is already a queued request to call the underlying function, it may be dropped - it is just guaranteed that we will try calling the underlying function as soon as possible starting from now.

type Runner Uses

type Runner struct {
    // contains filtered or unexported fields

Runner is an abstraction to make it easy to start and stop groups of things that can be described by a single function which waits on a channel close to exit.

func NewRunner Uses

func NewRunner(f ...func(stop chan struct{})) *Runner

NewRunner makes a runner for the given function(s). The function(s) should loop until the channel is closed.

func (*Runner) Start Uses

func (r *Runner) Start()

Start begins running.

func (*Runner) Stop Uses

func (r *Runner) Stop()

Stop stops running.

Package async imports 5 packages (graph) and is imported by 44 packages. Updated 2019-08-26. Refresh now. Tools for package owners.