Documentation ¶
Index ¶
- func NewLogExitedCallback[T comparable](le *logrus.Entry) func(key string, routine Routine, data T, err error)
- type KeyWithData
- type Keyed
- func (k *Keyed[T]) GetKey(key string) (Routine, T)
- func (k *Keyed[T]) GetKeys() []string
- func (k *Keyed[T]) GetKeysWithData() []KeyWithData[T]
- func (k *Keyed[T]) RemoveKey(key string) bool
- func (k *Keyed[T]) ResetRoutine(key string, conds ...func(T) bool) (existed bool, reset bool)
- func (k *Keyed[T]) SetContext(ctx context.Context, restart bool)
- func (k *Keyed[T]) SetKey(key string, restart bool) bool
- func (k *Keyed[T]) SyncKeys(keys []string, restart bool)
- type KeyedRef
- type KeyedRefCount
- func (k *KeyedRefCount[T]) AddKeyRef(key string) (ref *KeyedRef[T], existed bool)
- func (k *KeyedRefCount[T]) GetKey(key string) (Routine, T)
- func (k *KeyedRefCount[T]) GetKeys() []string
- func (k *KeyedRefCount[T]) GetKeysWithData() []KeyWithData[T]
- func (k *KeyedRefCount[T]) ResetRoutine(key string, conds ...func(T) bool) (existed bool, reset bool)
- func (k *KeyedRefCount[T]) SetContext(ctx context.Context, restart bool)
- type Routine
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewLogExitedCallback ¶ added in v0.15.2
func NewLogExitedCallback[T comparable](le *logrus.Entry) func(key string, routine Routine, data T, err error)
NewLogExitedCallback returns a ExitedCb which logs when a controller exited.
Types ¶
type KeyWithData ¶ added in v0.15.0
type KeyWithData[T comparable] struct { // Key is the key. Key string // Data is the associated data. Data T }
KeyWithData is a key with associated data.
type Keyed ¶
type Keyed[T comparable] struct { // contains filtered or unexported fields }
Keyed manages a set of goroutines with associated Keys.
func NewKeyed ¶
func NewKeyed[T comparable]( ctorCb func(key string) (Routine, T), exitedCb func(key string, routine Routine, data T, err error), ) *Keyed[T]
NewKeyed constructs a new Keyed execution manager. Note: routines won't start until SetContext is called. exitedCb is called after a routine exits unexpectedly.
func NewKeyedWithLogger ¶ added in v0.15.2
func NewKeyedWithLogger[T comparable]( ctorCb func(key string) (Routine, T), le *logrus.Entry, ) *Keyed[T]
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. exitedCb is called after a routine exits unexpectedly.
func (*Keyed[T]) GetKey ¶ added in v0.15.0
GetKey returns the routine for the given key. Note: this is an instantaneous snapshot.
func (*Keyed[T]) GetKeys ¶ added in v0.15.0
GetKeys returns the list of keys registered with the Keyed instance. Note: this is an instantaneous snapshot.
func (*Keyed[T]) GetKeysWithData ¶ added in v0.15.0
func (k *Keyed[T]) GetKeysWithData() []KeyWithData[T]
GetKeysWithData returns the keys and the data for the keys. Note: this is an instantaneous snapshot.
func (*Keyed[T]) RemoveKey ¶ added in v0.15.0
RemoveKey removes the given key from the set, if it exists. Returns if it existed.
func (*Keyed[T]) ResetRoutine ¶ added in v0.15.0
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 (*Keyed[T]) 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 ¶ added in v0.15.0
type KeyedRef[T comparable] struct { // contains filtered or unexported fields }
KeyedRef is a reference to a key.
type KeyedRefCount ¶ added in v0.15.0
type KeyedRefCount[T comparable] struct { // contains filtered or unexported fields }
KeyedRefCount manages a list of running routines with reference counts.
func NewKeyedRefCount ¶ added in v0.15.0
func NewKeyedRefCount[T comparable]( ctorCb func(key string) (Routine, T), exitedCb func(key string, routine Routine, data T, err error), ) *KeyedRefCount[T]
NewKeyedRefCount constructs a new Keyed execution manager with reference counting. Note: routines won't start until SetContext is called.
func NewKeyedRefCountWithLogger ¶ added in v0.15.2
func NewKeyedRefCountWithLogger[T comparable]( ctorCb func(key string) (Routine, T), le *logrus.Entry, ) *KeyedRefCount[T]
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[T]) AddKeyRef ¶ added in v0.15.0
func (k *KeyedRefCount[T]) AddKeyRef(key string) (ref *KeyedRef[T], existed bool)
AddKeyRef adds a reference to the given key. Returns if the key already existed or not.
func (*KeyedRefCount[T]) GetKey ¶ added in v0.15.0
func (k *KeyedRefCount[T]) GetKey(key string) (Routine, T)
GetKey returns the routine for the given key. Note: this is an instantaneous snapshot.
func (*KeyedRefCount[T]) GetKeys ¶ added in v0.15.0
func (k *KeyedRefCount[T]) GetKeys() []string
GetKeys returns the list of keys registered with the Keyed instance. Note: this is an instantaneous snapshot.
func (*KeyedRefCount[T]) GetKeysWithData ¶ added in v0.15.0
func (k *KeyedRefCount[T]) GetKeysWithData() []KeyWithData[T]
GetKeysWithData returns the keys and the data for the keys. Note: this is an instantaneous snapshot.
func (*KeyedRefCount[T]) ResetRoutine ¶ added in v0.15.0
func (k *KeyedRefCount[T]) ResetRoutine(key string, conds ...func(T) 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[T]) SetContext ¶ added in v0.15.0
func (k *KeyedRefCount[T]) SetContext(ctx context.Context, restart bool)
SetContext updates the root context, restarting all running routines. if restart is true, all errored routines also restart