event

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event interface{}

Event is the event interface.

type HandlerFn

type HandlerFn func(e Event)

HandleFn is an event handler func.

type Manager

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

Manager is an event manager to subscribe to and fire events.

func NewManager

func NewManager() *Manager

NewManager returns a new event Manager.

func (*Manager) Fire

func (m *Manager) Fire(event Event)

Fire fires an event and returns after all subscribers are complete handling it. Any panic by a subscriber is caught so firing the event to the next subscriber can proceed .

func (*Manager) FireParallel

func (m *Manager) FireParallel(event Event, after ...HandlerFn)

FireParallel fires an event in a new goroutine and returns immediately. It optionally runs handlers after all subscribers are done and passes the potentially modified version of the fired event. If an after handler panics no further handlers in the slice will be run.

func (*Manager) Subscribe

func (m *Manager) Subscribe(eventType Type, priority int, fn HandlerFn) (unsubscribe func())

Subscribe subscribes a handler to an event type with a priority and returns a func that can be run to unsubscribe.

HandlerFn should return quick and start long running tasks in parallel (e.g. if the event has a proxy.Inbound/proxy.Player then use its Close method to get notified when to cancel background work).

func (*Manager) Wait

func (m *Manager) Wait()

Wait blocks until no event subscribers are running.

type Type

type Type reflect.Type

Type is an event type.

func TypeOf

func TypeOf(e Event) Type

TypeOf is a helper func to make sure the reflect.Type implements the Event interface and returns a non-pointer type.

Jump to

Keyboard shortcuts

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