Documentation ¶
Overview ¶
Package event implements an event multiplexer.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrMuxClosed = errors.New("event: mux closed")
ErrMuxClosed is returned when Posting on a closed TypeMux.
Functions ¶
This section is empty.
Types ¶
type Subscription ¶
type Subscription interface { // Chan returns a channel that carries events. // Implementations should return the same channel // for any subsequent calls to Chan. Chan() <-chan interface{} // Unsubscribe stops delivery of events to a subscription. // The event channel is closed. // Unsubscribe can be called more than once. Unsubscribe() }
Subscription is implemented by event subscriptions.
type TypeMux ¶
type TypeMux struct {
// contains filtered or unexported fields
}
A TypeMux dispatches events to registered receivers. Receivers can be registered to handle events of certain type. Any operation called after mux is stopped will return ErrMuxClosed.
The zero value is ready to use.
Example ¶
Output: Received: event.someEvent{I:5} Received: event.someEvent{I:6} Received: event.otherEvent{S:"whoa"} done
func (*TypeMux) Post ¶
Post sends an event to all receivers registered for the given type. It returns ErrMuxClosed if the mux has been stopped.
func (*TypeMux) Stop ¶
func (mux *TypeMux) Stop()
Stop closes a mux. The mux can no longer be used. Future Post calls will fail with ErrMuxClosed. Stop blocks until all current deliveries have finished.
func (*TypeMux) Subscribe ¶
func (mux *TypeMux) Subscribe(types ...interface{}) Subscription
Subscribe creates a subscription for events of the given types. The subscription's channel is closed when it is unsubscribed or the mux is closed.