Documentation
¶
Index ¶
- Variables
- func Emit[T Event](ev T)
- func On[T Event](handler func(T)) context.CancelFunc
- func OnType[T Event](eventType uint32, handler func(T)) context.CancelFunc
- func Publish[T Event](broker *Dispatcher, ev T)
- func Subscribe[T Event](broker *Dispatcher, handler func(T)) context.CancelFunc
- func SubscribeTo[T Event](broker *Dispatcher, eventType uint32, handler func(T)) context.CancelFunc
- type Dispatcher
- type Event
Constants ¶
This section is empty.
Variables ¶
var Default = NewDispatcher()
Default initializes a default in-process dispatcher
Functions ¶
func Emit ¶
func Emit[T Event](ev T)
Emit writes an event into the dispatcher. This functions same way as Publish() but uses the default dispatcher instead.
func On ¶
func On[T Event](handler func(T)) context.CancelFunc
On subscribes to an event, the type of the event will be automatically inferred from the provided type. Must be constant for this to work. This functions same way as Subscribe() but uses the default dispatcher instead.
func OnType ¶
func OnType[T Event](eventType uint32, handler func(T)) context.CancelFunc
OnType subscribes to an event with the specified event type. This functions same way as SubscribeTo() but uses the default dispatcher instead.
func Publish ¶
func Publish[T Event](broker *Dispatcher, ev T)
Publish writes an event into the dispatcher
func Subscribe ¶
func Subscribe[T Event](broker *Dispatcher, handler func(T)) context.CancelFunc
Subscribe subscribes to an event, the type of the event will be automatically inferred from the provided type. Must be constant for this to work.
func SubscribeTo ¶
func SubscribeTo[T Event](broker *Dispatcher, eventType uint32, handler func(T)) context.CancelFunc
SubscribeTo subscribes to an event with the specified event type.
Types ¶
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher represents an event dispatcher.
func NewDispatcher ¶
func NewDispatcher() *Dispatcher
NewDispatcher creates a new dispatcher of events.