Documentation ¶
Index ¶
- func NewLogExitedCallback[K comparable, V any](le *logrus.Entry) func(key K, routine Routine, data V, err error)
- type KeyWithData
- type Keyed
- func (k *Keyed[K, V]) GetKey(key K) (V, bool)
- func (k *Keyed[K, V]) GetKeys() []K
- func (k *Keyed[K, V]) GetKeysWithData() []KeyWithData[K, V]
- func (k *Keyed[K, V]) RemoveKey(key K) bool
- func (k *Keyed[K, V]) ResetRoutine(key K, conds ...func(V) bool) (existed bool, reset bool)
- func (k *Keyed[K, V]) RestartRoutine(key K, conds ...func(V) bool) (existed bool, reset bool)
- func (k *Keyed[K, V]) SetContext(ctx context.Context, restart bool)
- func (k *Keyed[K, V]) SetKey(key K, start bool) (V, bool)
- func (k *Keyed[K, V]) SyncKeys(keys []K, restart bool)
- type KeyedRef
- type KeyedRefCount
- func (k *KeyedRefCount[K, V]) AddKeyRef(key K) (ref *KeyedRef[K, V], data V, existed bool)
- func (k *KeyedRefCount[K, V]) GetKey(key K) (V, bool)
- func (k *KeyedRefCount[K, V]) GetKeys() []K
- func (k *KeyedRefCount[K, V]) GetKeysWithData() []KeyWithData[K, V]
- func (k *KeyedRefCount[K, V]) ResetRoutine(key K, conds ...func(V) bool) (existed bool, reset bool)
- func (k *KeyedRefCount[K, V]) RestartRoutine(key K, conds ...func(V) bool) (existed bool, reset bool)
- func (k *KeyedRefCount[K, V]) SetContext(ctx context.Context, restart bool)
- type Option
- type Routine
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewLogExitedCallback ¶
func NewLogExitedCallback[K comparable, V any](le *logrus.Entry) func(key K, routine Routine, data V, err error)
NewLogExitedCallback returns a ExitedCb which logs when a controller exited.
Types ¶
type KeyWithData ¶
type KeyWithData[K comparable, V any] struct { // Key is the key. Key K // Data is the value. Data V }
KeyWithData is a key with associated data.
type Keyed ¶
type Keyed[K comparable, V any] struct { // contains filtered or unexported fields }
Keyed manages a set of goroutines with associated Keys.
K is the type of the key. V is the type of the value.
func NewKeyed ¶
func NewKeyed[K comparable, V any]( ctorCb func(key K) (Routine, V), opts ...Option[K, V], ) *Keyed[K, V]
NewKeyed constructs a new Keyed execution manager. Note: routines won't start until SetContext is called.
func NewKeyedWithLogger ¶
func NewKeyedWithLogger[K comparable, V any]( ctorCb func(key K) (Routine, V), le *logrus.Entry, ) *Keyed[K, V]
NewKeyedWithLogger constructs a new keyed instance. Logs when a controller exits without being removed from the Keys set.
Note: routines won't start until SetContext is called.
func (*Keyed[K, V]) GetKeys ¶
func (k *Keyed[K, V]) GetKeys() []K
GetKeys returns the list of keys registered with the Keyed instance.
func (*Keyed[K, V]) GetKeysWithData ¶
func (k *Keyed[K, V]) GetKeysWithData() []KeyWithData[K, V]
GetKeysWithData returns the keys and the data for the keys.
func (*Keyed[K, V]) RemoveKey ¶
RemoveKey removes the given key from the set, if it exists. Returns if it existed.
func (*Keyed[K, V]) ResetRoutine ¶
ResetRoutine resets the given routine after checking the condition functions. If any of the conds functions return true, resets the instance.
Resetting the instance constructs a new Routine and data with the constructor. Note: this will overwrite the existing Data, if present! In most cases RestartRoutine is actually what you want.
If len(conds) == 0, always resets the given key.
func (*Keyed[K, V]) RestartRoutine ¶
RestartRoutine restarts the given routine after checking the condition functions. If any return true, and the routine is running, restarts the instance.
If len(conds) == 0, always resets the given key.
func (*Keyed[K, V]) SetContext ¶
SetContext updates the root context, restarting all running routines. If ctx == nil, stops all routines. if restart is true, all errored routines also restart
type KeyedRef ¶
type KeyedRef[K comparable, V any] struct { // contains filtered or unexported fields }
KeyedRef is a reference to a key.
type KeyedRefCount ¶
type KeyedRefCount[K comparable, V any] struct { // contains filtered or unexported fields }
KeyedRefCount manages a list of running routines with reference counts.
func NewKeyedRefCount ¶
func NewKeyedRefCount[K comparable, V any]( ctorCb func(key K) (Routine, V), opts ...Option[K, V], ) *KeyedRefCount[K, V]
NewKeyedRefCount constructs a new Keyed execution manager with reference counting. Note: routines won't start until SetContext is called.
func NewKeyedRefCountWithLogger ¶
func NewKeyedRefCountWithLogger[K comparable, V any]( ctorCb func(key K) (Routine, V), le *logrus.Entry, ) *KeyedRefCount[K, V]
NewKeyedRefCountWithLogger constructs a new Keyed execution manager with reference counting. Logs when a controller exits without being removed from the Keys set. Note: routines won't start until SetContext is called.
func (*KeyedRefCount[K, V]) AddKeyRef ¶
func (k *KeyedRefCount[K, V]) AddKeyRef(key K) (ref *KeyedRef[K, V], data V, existed bool)
AddKeyRef adds a reference to the given key. Returns if the key already existed or not.
func (*KeyedRefCount[K, V]) GetKey ¶
func (k *KeyedRefCount[K, V]) GetKey(key K) (V, bool)
GetKey returns the value for the given key and if it existed.
func (*KeyedRefCount[K, V]) GetKeys ¶
func (k *KeyedRefCount[K, V]) GetKeys() []K
GetKeys returns the list of keys registered with the Keyed instance.
func (*KeyedRefCount[K, V]) GetKeysWithData ¶
func (k *KeyedRefCount[K, V]) GetKeysWithData() []KeyWithData[K, V]
GetKeysWithData returns the keys and the data for the keys.
func (*KeyedRefCount[K, V]) ResetRoutine ¶
func (k *KeyedRefCount[K, V]) ResetRoutine(key K, conds ...func(V) bool) (existed bool, reset bool)
ResetRoutine resets the given routine after checking the condition functions. If any return true, resets the instance.
If len(conds) == 0, always resets the given key.
func (*KeyedRefCount[K, V]) RestartRoutine ¶
func (k *KeyedRefCount[K, V]) RestartRoutine(key K, conds ...func(V) bool) (existed bool, reset bool)
RestartRoutine restarts the given routine after checking the condition functions. If any return true, and the routine is running, restarts the instance.
If len(conds) == 0, always resets the given key.
func (*KeyedRefCount[K, V]) SetContext ¶
func (k *KeyedRefCount[K, V]) SetContext(ctx context.Context, restart bool)
SetContext updates the root context, restarting all running routines. if restart is true, all errored routines also restart
type Option ¶
type Option[K comparable, V any] interface { // ApplyToKeyed applies the option to the Keyed. ApplyToKeyed(k *Keyed[K, V]) }
Option is an option for a Keyed instance.
func WithExitCb ¶
func WithExitCb[K comparable, V any](cb func(key K, routine Routine, data V, err error)) Option[K, V]
WithExitCb adds a callback after a routine exits.
func WithExitLogger ¶
func WithExitLogger[K comparable, V any](le *logrus.Entry) Option[K, V]
WithExitLogger adds a exited callback which logs information about the exit.
func WithReleaseDelay ¶
func WithReleaseDelay[K comparable, V any](delay time.Duration) Option[K, V]
WithReleaseDelay adds a delay after removing a key before canceling the routine.