runner

package
v1.35.0-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoundedFrequencyRunner

type BoundedFrequencyRunner struct {
	// contains filtered or unexported fields
}

BoundedFrequencyRunner manages runs of a user-provided work function.

func NewBoundedFrequencyRunner

func NewBoundedFrequencyRunner(name string, fn func() error, minInterval, retryInterval, maxInterval time.Duration) *BoundedFrequencyRunner

NewBoundedFrequencyRunner creates and returns a new BoundedFrequencyRunner. This runner manages the execution frequency of the provided function `fn`.

The runner guarantees two properties:

  1. Minimum Interval (`minInterval`): At least `minInterval` must pass between the *completion* of one execution and the *start* of the next. Calls to `Run()` during this cooldown period are coalesced and deferred until the interval expires. This prevents burst executions.
  2. Maximum Interval (`maxInterval`): The function `fn` is guaranteed to run at least once per `maxInterval`, ensuring periodic execution even without explicit `Run()` calls (e.g., for refreshing state).

`maxInterval` must be greater than or equal to `minInterval`; otherwise, this function will panic.

If `fn` returns an error, then it will be run again no later than `retryInterval` (unless another trigger, like `Run()` or `maxInterval`, causes it to run sooner). Any successful run will abort the retry attempt.

func (*BoundedFrequencyRunner) Loop

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

func (bfr *BoundedFrequencyRunner) Run()

Run the work function as soon as possible. If this is called while Loop is not running, the call may be deferred indefinitely. Once there is a queued request to call the work function, further calls to Run() will have no effect until after it runs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL