Documentation ¶
Overview ¶
Package state deals with tracking, notification, and management of state and state changes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrTerminalState = errors.New("terminal state")
ErrTerminalState is returned from Stateful.WaitForStateChange if the currentState is a terminal state.
Functions ¶
func IsTerminal ¶
IsTerminal returns whether state implements Terminal and returns true for Terminal.IsTerminal.
Types ¶
type Manager ¶
type Manager[T comparable] struct { // contains filtered or unexported fields }
Manager keeps track of changes to state.
func NewManager ¶
func NewManager[T comparable](initialState T) *Manager[T]
NewManager returns a new Manager with an initial state.
func (*Manager[T]) CurrentState ¶
func (sm *Manager[T]) CurrentState() T
CurrentState returns the current state.
func (*Manager[T]) GetNotifyChan ¶
func (sm *Manager[T]) GetNotifyChan() <-chan struct{}
GetNotifyChan returns a chan that can be used to be notified when the state changes.
type Stateful ¶
type Stateful[S comparable] interface { // WaitForStateChange waits until the state changes from sourceState or ctx expires. // An error will be returned if ctx expires or the state will never change. WaitForStateChange(ctx context.Context, sourceState S) error // CurrentState returns the current state. CurrentState() S }
Stateful describes types that have a single state.
Click to show internal directories.
Click to hide internal directories.