events

package
v0.0.0-...-25ef478 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2023 License: Apache-2.0, BSD-2-Clause Imports: 11 Imported by: 118

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolCaller

func BoolCaller(handler interface{}, params ...interface{})

func ByteCaller

func ByteCaller(handler interface{}, params ...interface{})

func ByteSliceCaller

func ByteSliceCaller(handler interface{}, params ...interface{})

func ErrorCaller

func ErrorCaller(handler interface{}, params ...interface{})

func Int16Caller

func Int16Caller(handler interface{}, params ...interface{})

func Int16SliceCaller

func Int16SliceCaller(handler interface{}, params ...interface{})

func Int32Caller

func Int32Caller(handler interface{}, params ...interface{})

func Int32SliceCaller

func Int32SliceCaller(handler interface{}, params ...interface{})

func Int64Caller

func Int64Caller(handler interface{}, params ...interface{})

func Int64SliceCaller

func Int64SliceCaller(handler interface{}, params ...interface{})

func Int8Caller

func Int8Caller(handler interface{}, params ...interface{})

func Int8SliceCaller

func Int8SliceCaller(handler interface{}, params ...interface{})

func IntCaller

func IntCaller(handler interface{}, params ...interface{})

func IntSliceCaller

func IntSliceCaller(handler interface{}, params ...interface{})

func StringCaller

func StringCaller(handler interface{}, params ...interface{})

func StringSliceCaller

func StringSliceCaller(handler interface{}, params ...interface{})

func Uint16Caller

func Uint16Caller(handler interface{}, params ...interface{})

func Uint16SliceCaller

func Uint16SliceCaller(handler interface{}, params ...interface{})

func Uint32Caller

func Uint32Caller(handler interface{}, params ...interface{})

func Uint32SliceCaller

func Uint32SliceCaller(handler interface{}, params ...interface{})

func Uint64Caller

func Uint64Caller(handler interface{}, params ...interface{})

func Uint64SliceCaller

func Uint64SliceCaller(handler interface{}, params ...interface{})

func Uint8Caller

func Uint8Caller(handler interface{}, params ...interface{})

func Uint8SliceCaller

func Uint8SliceCaller(handler interface{}, params ...interface{})

func VoidCaller

func VoidCaller(handler interface{}, params ...interface{})

func WaitForChannelClosed

func WaitForChannelClosed(ctx context.Context, ch chan struct{}) error

WaitForChannelClosed waits until the channel is closed or the context is done. If the context was done, the event should be manually deregistered afterwards to clean up memory.

Types

type Closure

type Closure struct {
	ID  uint64
	Fnc interface{}
}

func NewClosure

func NewClosure(f interface{}) *Closure

type Event

type Event struct {
	// contains filtered or unexported fields
}

Event represents an object that is triggered to notify code of "interesting updates" that may affect its behavior.

func NewEvent

func NewEvent(triggerFunc func(handler interface{}, params ...interface{})) *Event

NewEvent is the constructor of an Event.

func (*Event) Detach

func (ev *Event) Detach(closure *Closure)

Detach allows to unregister a Closure that was previously registered.

func (*Event) DetachAll

func (ev *Event) DetachAll()

DetachAll removes all registered callbacks.

func (*Event) DetachID

func (ev *Event) DetachID(closureID uint64)

DetachID allows to unregister a Closure ID that was previously registered.

func (*Event) Hook

func (ev *Event) Hook(closure *Closure, triggerMaxCount ...uint64)

Hook allows to register a Closure that is executed when the Event triggers. If 'triggerMaxCount' is >0, the Closure is automatically detached after exceeding the trigger limit.

func (*Event) HookAfter

func (ev *Event) HookAfter(closure *Closure, triggerMaxCount ...uint64)

HookAfter allows to register a Closure that is executed after the Event triggered. If 'triggerMaxCount' is >0, the Closure is automatically detached after exceeding the trigger limit.

func (*Event) HookBefore

func (ev *Event) HookBefore(closure *Closure, triggerMaxCount ...uint64)

HookBefore allows to register a Closure that is executed before the Event triggers. If 'triggerMaxCount' is >0, the Closure is automatically detached after exceeding the trigger limit.

func (*Event) Trigger

func (ev *Event) Trigger(params ...interface{})

Trigger calls the registered callbacks with the given parameters.

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

Queue represents an Event

func NewQueue

func NewQueue() *Queue

NewQueue returns an empty Queue.

func (*Queue) Clear

func (q *Queue) Clear()

Clear removes all elements from the Queue.

func (*Queue) Queue

func (q *Queue) Queue(event *Event, params ...interface{})

Queue enqueues an Event to be triggered later (using the Trigger function).

func (*Queue) Trigger

func (q *Queue) Trigger()

Trigger triggers all queued Events and empties the Queue.

type SyncEvent

type SyncEvent struct {
	syncutils.RWMutex
	// contains filtered or unexported fields
}

func NewSyncEvent

func NewSyncEvent() *SyncEvent

func (*SyncEvent) DeregisterEvent

func (se *SyncEvent) DeregisterEvent(key interface{})

DeregisterEvent removes a registered event to free the memory if not used.

func (*SyncEvent) RegisterEvent

func (se *SyncEvent) RegisterEvent(key interface{}) chan struct{}

RegisterEvent creates a unique channel for the key which can be used to signal global events.

func (*SyncEvent) Trigger

func (se *SyncEvent) Trigger(key interface{})

type ThresholdEvent

type ThresholdEvent struct {
	*Event
	// contains filtered or unexported fields
}

ThresholdEvent is a data structure that acts like a normal event but only triggers when the value that was reported using the Set method causes the corresponding identifier to reach a new threshold. It is stateful which means that it tracks the current level for all identifiers individually to not trigger the same event multiple times.

func NewThresholdEvent

func NewThresholdEvent(options ...ThresholdEventOption) (thresholdEvent *ThresholdEvent)

NewThresholdEvent is the constructor for the ThresholdEvent.

func ThresholdEventFromBytes

func ThresholdEventFromBytes(bytes []byte, options ...ThresholdEventOption) (thresholdEvent *ThresholdEvent, consumedBytes int, err error)

ThresholdEventFromBytes unmarshals a collection of BranchIDs from a sequence of bytes.

func ThresholdEventFromMarshalUtil

func ThresholdEventFromMarshalUtil(marshalUtil *marshalutil.MarshalUtil, options ...ThresholdEventOption) (thresholdEvent *ThresholdEvent, err error)

ThresholdEventFromMarshalUtil unmarshals a ThresholdEvent using a MarshalUtil (for easier unmarshaling).

func (*ThresholdEvent) Bytes

func (t *ThresholdEvent) Bytes() []byte

Bytes returns a marshaled version of the ThresholdEvent.

func (*ThresholdEvent) Level

func (t *ThresholdEvent) Level(identifier ThresholdEventIdentifier) (level int)

Level returns the current level of the reached threshold for the given identity.

func (*ThresholdEvent) Set

func (t *ThresholdEvent) Set(identifier ThresholdEventIdentifier, newValue float64) (newLevel int, transition ThresholdEventTransition)

Set updates the value associated with the given identifier and triggers the Event if necessary.

type ThresholdEventCallbackTypecaster

type ThresholdEventCallbackTypecaster func(handler interface{}, identifier interface{}, newLevel int, transition ThresholdEventTransition)

ThresholdEventCallbackTypecaster defines the signature of the function that is used to convert the parameters to the types expected by the callbacks.

type ThresholdEventConfiguration

type ThresholdEventConfiguration struct {
	Thresholds         []float64
	CallbackTypecaster ThresholdEventCallbackTypecaster
	IdentifierParser   ThresholdEventIdentifierParser
}

ThresholdEventConfiguration represents a collection of optional parameters that are used by the ThresholdEvent.

func NewThresholdEventConfiguration

func NewThresholdEventConfiguration(options ...ThresholdEventOption) (configuration *ThresholdEventConfiguration)

NewThresholdEventConfiguration creates a ThresholdEventConfiguration from the given Options.

type ThresholdEventIdentifier

type ThresholdEventIdentifier marshalutil.SimpleBinaryMarshaler

ThresholdEventIdentifier is the type that is used to address the identifiers of the entities whose values we are tracking.

type ThresholdEventIdentifierParser

type ThresholdEventIdentifierParser func(marshalUtil *marshalutil.MarshalUtil) (identifier interface{}, err error)

ThresholdEventIdentifierParser defines the signature of the function that is used to parse the Identifiers.

type ThresholdEventOption

type ThresholdEventOption func(*ThresholdEventConfiguration)

ThresholdEventOption is the type of the optional parameters of the ThresholdEvent.

func WithCallbackTypeCaster

func WithCallbackTypeCaster(callbackTypeCaster ThresholdEventCallbackTypecaster) ThresholdEventOption

WithCallbackTypeCaster sets the method that is used to type cast the called callbacks to their correct types.

func WithIdentifierParser

func WithIdentifierParser(identifierParser ThresholdEventIdentifierParser) ThresholdEventOption

WithIdentifierParser sets the parser for the ThresholdEventIdentifier that is used to identify different entities.

func WithThresholds

func WithThresholds(thresholds ...float64) ThresholdEventOption

WithThresholds sets the thresholds that are supposed to be used for the Triggers.

type ThresholdEventTransition

type ThresholdEventTransition int

ThresholdEventTransition is the type of the values that are used to indicate in which direction a threshold was passed.

const (
	// ThresholdLevelMaintained indicates that the reached threshold did not change.
	ThresholdLevelMaintained ThresholdEventTransition = 0

	// ThresholdLevelIncreased indicates that the new value is larger than the passed threshold.
	ThresholdLevelIncreased ThresholdEventTransition = 1

	// ThresholdLevelDecreased indicates that the new value is smaller than the passed threshold.
	ThresholdLevelDecreased ThresholdEventTransition = -1
)

func (ThresholdEventTransition) String

func (t ThresholdEventTransition) String() string

String returns a human readable version of the ThresholdEventTransition.

Jump to

Keyboard shortcuts

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