event

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: Apache-2.0, BSD-2-Clause Imports: 7 Imported by: 46

Documentation

Index

Constants

This section is empty.

Variables

Functions

func Attach

func Attach[T any](event *Linkable[T], callback func(event T), triggerMaxCount ...uint64) (detachFunc func())

func AttachWithWorkerPool

func AttachWithWorkerPool[T any](event *Linkable[T], callback func(event T), wp *workerpool.UnboundedWorkerPool, triggerMaxCount ...uint64) (detachFunc func())

func Hook

func Hook[T any](event *Linkable[T], callback func(event T), triggerMaxCount ...uint64) (detachFunc func())

func LinkableConstructor

func LinkableConstructor[A any, B ptrLinkableCollectionType[A, B]](newFunc func() B) (constructor func(...B) B)

LinkableConstructor returns the linkable constructor for the given type.

Types

type Closure

type Closure[T any] struct {
	ID       uint64
	Function func(event T)
}

Closure represents function reference uniquely.

func NewClosure

func NewClosure[T any](function func(event T)) *Closure[T]

NewClosure creates a new Closure.

type Event

type Event[T any] 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 New

func New[T any]() (newEvent *Event[T])

New creates a new Event.

func (*Event[T]) Attach

func (e *Event[T]) Attach(closure *Closure[T], triggerMaxCount ...uint64)

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

func (*Event[T]) AttachWithWorkerPool

func (e *Event[T]) AttachWithWorkerPool(closure *Closure[T], wp *workerpool.UnboundedWorkerPool, triggerMaxCount ...uint64)

AttachWithWorkerPool allows to register a Closure that is executed asynchronously in the specified worker pool when the Event triggers. If 'triggerMaxCount' is >0, the Closure is automatically detached after exceeding the trigger limit.

func (*Event[T]) Detach

func (e *Event[T]) Detach(closure *Closure[T])

Detach allows to unregister a Closure that was previously registered.

func (*Event[T]) DetachAll

func (e *Event[T]) DetachAll()

DetachAll removes all registered callbacks.

func (*Event[T]) Hook

func (e *Event[T]) Hook(closure *Closure[T], 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[T]) HookAfter

func (e *Event[T]) HookAfter(closure *Closure[T], 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[T]) HookBefore

func (e *Event[T]) HookBefore(closure *Closure[T], 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[T]) Trigger

func (e *Event[T]) Trigger(event T)

Trigger calls the registered callbacks with the given parameters.

type Linkable

type Linkable[A any] struct {
	*Event[A]
	// contains filtered or unexported fields
}

Linkable represents a special kind of Event that is part of a LinkableCollection of events.

func NewLinkable

func NewLinkable[A any]() (newEvent *Linkable[A])

NewLinkable creates a new Linkable.

func (*Linkable[A]) LinkTo

func (e *Linkable[A]) LinkTo(optLinkTargets ...*Linkable[A])

LinkTo links the Linkable to the given Linkable.

type LinkableCollection

type LinkableCollection[A any, B ptrLinkableCollectionType[A, B]] struct {
	sync.Once
	// contains filtered or unexported fields
}

LinkableCollection can be embedded into collections of linkable Events to make the entire collection linkable.

func (*LinkableCollection[A, B]) LinkTo

func (l *LinkableCollection[A, B]) LinkTo(optLinkTargets ...B)

LinkTo offers a way to link the collection to another collection of the same type.

Jump to

Keyboard shortcuts

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