Documentation
¶
Overview ¶
Package mint provides a tiny generic event emitter. Version under mint/context exposes context api.
e := new(mint.Emitter) // create an emitter
mint.On(e, func(MyEvent)) // subscribe to MyEvent
mint.Emit(e, MyEvent{ ... }) // emit values to consumers
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Emit ¶
Emit Sequentially pushes value v to all consumers of type T. Receive order is indetermenistic.
func On ¶
On Registers a new consumer that receives all values which were emitted as T. So that On(e, func(any)) will receive all values emitted with Emit[any](e, ...)
Call to off schedules consumer to stop once all concurrent Emits stop and returns a <-chan which will get closed once it is done. It is possible for consumer to receive values after a call to stop if other concurrent emits are ongoing.
func Use ¶
Use allows to hook into event emitting process. Plugins are called sequentially in order they were added to Emitter. Plugin is a function that takes Emitted values and returns nil or a function that will be called after all consumers got the Emitted value. Returned functions are called in reverse order via `defer` statement.