state

package
v0.0.0-...-b617ce4 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Loop

type Loop struct {
	// Startup runs on the loop's goroutine at the start of every run, before the
	// first cycle. What it returns runs when the run ends.
	Startup func() (cleanup func())

	// SerialRuns makes a new run wait for the previous one to have left its
	// cycle before it begins, which delays a restart by as long as a cycle can
	// last. Off by default, a run then begins while the previous one may still
	// be finishing.
	SerialRuns bool
	// contains filtered or unexported fields
}

Loop runs a cycle on its own goroutine until it is stopped, waiting between them either a fixed period or the duration the cycle itself returns. Start and Stop can be called in any order and as many times as needed.

Stop does not wait for the cycle under way: it asks the loop to end and returns.

func NewAdaptiveLoop

func NewAdaptiveLoop(name string, owner clock.ClockInterface, first time.Duration, cycle func() time.Duration) *Loop

NewAdaptiveLoop returns a Loop whose cycle returns how long to wait before the next one. first is the wait before the very first cycle.

func NewLoop

func NewLoop(name string, owner clock.ClockInterface, period time.Duration, cycle func()) *Loop

NewLoop returns a Loop running cycle every period.

func (*Loop) Start

func (loop *Loop) Start()

Start is a no-op when the loop is already running. The exported fields must not change once it has been called.

func (*Loop) Stop

func (loop *Loop) Stop()

Stop asks the loop to end and returns without waiting for the cycle under way.

type Startable

type Startable interface {
	Start()
}

type Stopable

type Stopable interface {
	Stop()
}

Jump to

Keyboard shortcuts

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