Documentation
¶
Index ¶
- type CState
- func (c *CState[T]) AddWatcher(ctx context.Context, initial bool, cb func(ctx context.Context, state T)) (func(), error)
- func (c *CState[T]) Apply(ctx context.Context, ...) (dirty bool, err error)
- func (c *CState[T]) Execute(ctx context.Context, errCh <-chan error) error
- func (c *CState[T]) Obj() T
- func (c *CState[T]) View(ctx context.Context, cb func(ctx context.Context, value T) error) (rerr error)
- func (c *CState[T]) Wait(ctx context.Context, cb func(ctx context.Context, val T) (bool, error)) error
- func (c *CState[T]) Wake(setDirty bool)
- type CStateWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CState ¶
type CState[T any] struct { // contains filtered or unexported fields }
CState maintains an operation queue and a set of watchers. If any operation returns true for "dirty" the watchers are called.
Allows a single operation to execute at a time.
func (*CState[T]) AddWatcher ¶
func (c *CState[T]) AddWatcher( ctx context.Context, initial bool, cb func(ctx context.Context, state T), ) (func(), error)
AddWatcher adds a watcher callback function. The state will be locked while the watcher executes. Called if the state changes (dirty=true). If initial=true, calls with initial value immediately. Returns a function to remove the watcher. The ctx is used to call the watcher, if canceled, watcher is removed. Returns an error only if ctx is canceled.
func (*CState[T]) Apply ¶
func (c *CState[T]) Apply( ctx context.Context, op func(ctx context.Context, v *CStateWriter[T]) (dirty bool, err error), ) (dirty bool, err error)
Apply queues & applies the given operation.
func (*CState[T]) Execute ¶
Execute executes the operation loop. errCh can be used to interrupt the Execute loop, and can be nil.
func (*CState[T]) View ¶
func (c *CState[T]) View( ctx context.Context, cb func(ctx context.Context, value T) error, ) (rerr error)
View calls a callback while the mutex is locked.
type CStateWriter ¶
CStateWriter is passed to the CState callback with a SetObj function.