Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConsumeFunc ¶
type ConsumeFunc func(Event)
ConsumeFunc is a callback signature for managing received events. It receives a read-only copy of an event from listening session.
type DefaultListener ¶
type DefaultListener struct {
// contains filtered or unexported fields
}
DefaultListener encapsulates a common event listening logic (one subscriber to many publishers; a single channel will be used as a communication bridge) and supports multiple listening sessions.
func DefaultListenerInstance ¶
func DefaultListenerInstance() *DefaultListener
DefaultListenerInstance returns a reference to the static DefaultListener instance.
func NewDefaultListener ¶
func NewDefaultListener() *DefaultListener
NewDefaultListener returns a reference to the newly created DefaultListener instance.
func (*DefaultListener) Listen ¶
func (l *DefaultListener) Listen(fn ConsumeFunc) (ROListenerSession, error)
Listen method starts and returns a new listening session with notification channel to which senders should push their events; stops listening when the notify channel becomes closed.
type Event ¶
type Event struct { // The event type to decide receiver's logic. Type EventType // A custom data payload. Payload interface{} }
Event represents a message in pubsub pattern with type information and a custom data payload.
func WithTypeAndPayload ¶
WithTypeAndPayload is a constructor that returns a new event with specified type and data payload.
type Listener ¶
type Listener interface {
Listen(ConsumeFunc) (ROListenerSession, error)
}
Listener receives events (e.g. from workers) and calls a specified closure for processing. The Listen method returns a read-only listening session instance that exposes a communication channel between sender(s) and related event listener.
Usage example:
listenerSession, listenErr := eventListener.Listen(func(e Event) {}) if listenErr != nil { // Handle error. } var notifyChannel chan<- Event = listenerSession.NotifyChannel() notifyChannel <- Event{} listenerSession.Close() // Use this method to close the channel safely.
type ROListenerSession ¶
type ROListenerSession struct {
// contains filtered or unexported fields
}
ROListenerSession is a read-only listener session that's used as a bridge between event listener and sender(s) (e.g. worker); a caller should pass the notification channel associated with listening session to the sender(s) to start communication via events.
func MustListen ¶ added in v0.2.0
func MustListen(fn ConsumeFunc) ROListenerSession
MustListen is a shortcut for starting a common event listener session. It will abort the program execution if any error occurs.
func (ROListenerSession) Close ¶
func (ls ROListenerSession) Close()
Close method should be used to safely close the notification channel and stop the event listening session.
func (ROListenerSession) NotifyChannel ¶
func (ls ROListenerSession) NotifyChannel() chan<- Event
NotifyChannel method returns a notification channel for sending events.