Documentation ¶
Overview ¶
Package event provides a system for broadcasting events to multiple event handlers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Broadcaster ¶
type Broadcaster[L any] struct { // contains filtered or unexported fields }
Broadcaster manages event listeners.
func (*Broadcaster[L]) Connect ¶
func (broadcaster *Broadcaster[L]) Connect(listener L) Cookie
Connect adds a new listener to the broadcaster and returns a corresponding Cookie.
func (*Broadcaster[L]) Listeners ¶ added in v0.6.0
func (broadcaster *Broadcaster[L]) Listeners() map[int]L
Listeners returns a map of all connected listeners.
type Cookie ¶
Cookie is returned when you add an event handler so you can remove it later if you so choose. When the Close behavior is called, the handler must be removed, even if an error is returned.
func MultiCookie ¶ added in v0.19.0
MultiCookie creates a single cookie that, when closed, closes a list of other cookies.
type FuncBroadcaster ¶ added in v0.6.0
type FuncBroadcaster struct { Broadcaster[func()] }
FuncBroadcaster is a Broadcaster that manages functions with no arguments.
func (*FuncBroadcaster) Broadcast ¶ added in v0.6.0
func (broadcaster *FuncBroadcaster) Broadcast()
Broadcast calls all connected listener funcs.
type FuncCookie ¶ added in v0.47.0
type FuncCookie func() error
FuncCookie is a cookie that calls a function (itself) when closed.
func (FuncCookie) Close ¶ added in v0.47.0
func (cookie FuncCookie) Close() error