event

package
v1.0.0-beta.3 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2022 License: Apache-2.0, BSD-2-Clause Imports: 4 Imported by: 48

Documentation

Index

Constants

This section is empty.

Variables

Functions

This section is empty.

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]) 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.

Jump to

Keyboard shortcuts

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