Documentation ¶
Overview ¶
Package event provides lightweight primitives for event-bus-consumer communication.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bus ¶
Bus is a event-consumer communication layer. It manages events publications and handling, its synchronous and safe to use from multiple goroutines. Use NewBus() func to get an instance of it.
func (*Bus) Clear ¶
Clear assigns new map value to bus consumers and returns old ones. The modification of returned map won't affect bus consumers.
func (*Bus) Rm ¶
Rm removes given consumer from the bus, == operator is used to determine what elements should be removed. Returns true if consumer is removed.
func (*Bus) RmIf ¶
RmIf removes consumers for which predicate func returns true. Returns true if any consumer was removed.
type Consumer ¶
type Consumer interface { // Accept handles given event. Accept(event E) }
Consumer is an interface for event handlers.
type ConsumerF ¶
type ConsumerF func(event E)
ConsumerF is a function which is also consumer, allows to use anonymous functions as consumers.
type E ¶
type E interface { // Type returns a type of this event. // Bus uses returned type to retrieve and notify consumers. Type() string }
E is an interface for event. Only instances of this interface can be published in Bus.
type TmpConsumer ¶
type TmpConsumer interface { Consumer // IsDone called by bus after accept, if func returns true // this consumer will be removed from bus. IsDone() bool }
TmpConsumer allows consumer to be removed from bus each time after accept. Accept is called at least once for such consumers.