Documentation
¶
Overview ¶
Package mint provides a tiny generic event emitter.
e := new(mint.Emitter) // create an emitter mint.On(e, func(context.Context, MyEvent)) // subscribe to MyEvent mint.Emit(e, context.Background(), 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. Cancelling ctx waits for active consumer to return and stops emitting further.
Using nil context will use context.Background() instead. error is always ctx.Err()
func On ¶
On Registers a new consumer that receives all values which were emitted as T. So that On(e, func(context.Context, any)) will receive all values emitted with Emit[any](e, ...)
Reliance on a certain value to be present in the context signals that it should be included in T.
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.