Documentation
¶
Overview ¶
Package events provides types to implement busses of events in an application. Senders can send events on these busses and receiver receive the events. What differenciate such a bus from a Go channel is that each event is dispatched to all receiver.
By providing a central busses to different parts of the application, these parts can communicate together without knowing each other.
Index ¶
Constants ¶
const DefaultManagerChannelSize = 256
Variables ¶
var (
ManagerClosedError = errors.New("The manager is closed")
)
Errors
Functions ¶
This section is empty.
Types ¶
type AsyncForwarder ¶
type AsyncForwarder struct {
// Filter returns true for events that must be forwarded through the channel.
Filter func(Event) bool
Chan chan<- Event
}
AsyncForwarder is a simple Receiver that forward events through a channel.
func (AsyncForwarder) Close ¶
func (self AsyncForwarder) Close()
func (AsyncForwarder) Receive ¶
func (self AsyncForwarder) Receive(evt Event)
type Manager ¶
type Manager interface {
// Send dispatch an event to all the Receivers of the Manager.
// It takes ownership of the event.
Send(Event) error
// AddReceiver registers a Receiver to receive all events sent to the Manager.
// If the Receiver is added to more than one Manager, it must be goroutine-safe.
AddReceiver(Receiver) error
// Close stops the Manager. Any subsequent Send will result in an error.
// The Close method of all the Receivers of the Manager will eventually be called.
Close() error
}
Manager dispatches events from senders to Receivers.
All its method must be goroutine-safe.
func NewAsyncManager ¶
NewAsyncManager creates a new asynchronous Manager.
An asynchronous manager launch a goroutine that calls the Receive method of all the registered receivers for each sent event. Events are sent to this goroutine through a channel whose size is given as argument to NewAsyncManager.
type Receiver ¶
type Receiver interface {
Receive(Event)
Close()
}
Receiver receives events from a Manager.
It can be assumed that the methods of a given Receiver are always called from the same goroutine by the Manager.
type ReceiverFunc ¶
type ReceiverFunc func(Event)
ReceiverFunc turn a function into a stateless Receiver, whose Close method does nothing.
func (ReceiverFunc) Close ¶
func (self ReceiverFunc) Close()
func (ReceiverFunc) Receive ¶
func (self ReceiverFunc) Receive(evt Event)