Documentation ¶
Index ¶
- Constants
- func AnyUser() *id.ID
- type Listener
- type ListenerFunc
- type ListenerID
- type Message
- type Switchboard
- func (sw *Switchboard) RegisterChannel(name string, user *id.ID, messageType catalog.MessageType, ...) ListenerID
- func (sw *Switchboard) RegisterFunc(name string, user *id.ID, messageType catalog.MessageType, ...) ListenerID
- func (sw *Switchboard) RegisterListener(user *id.ID, messageType catalog.MessageType, newListener Listener) ListenerID
- func (sw *Switchboard) Speak(item Message)
- func (sw *Switchboard) Unregister(listenerID ListenerID)
- func (sw *Switchboard) UnregisterUserListeners(userID *id.ID)
Constants ¶
const AnyType = catalog.NoType
ID to respond to any message type
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Listener ¶
type Listener interface { // the Hear function is called to exercise the listener, passing in the // data as an item Hear(item Message) // Returns a name, used for debugging Name() string }
Listener interface for a listener adhere to
type ListenerFunc ¶
type ListenerFunc func(item Message)
ListenerFunc This function type defines callbacks that get passed when the listener is listened to. It will always be called in its own goroutine. It may be called multiple times simultaneously
type ListenerID ¶
type ListenerID struct {
// contains filtered or unexported fields
}
ListenerID id object returned when a listener is created and is used to delete it from the system
func (ListenerID) GetMessageType ¶
func (lid ListenerID) GetMessageType() catalog.MessageType
GetMessageType getter for message type
func (ListenerID) String ¶
func (lid ListenerID) String() string
String returns the values in the ListenerID in a human-readable format. This functions adheres to the fmt.Stringer interface.
type Switchboard ¶
type Switchboard struct {
// contains filtered or unexported fields
}
func (*Switchboard) RegisterChannel ¶
func (sw *Switchboard) RegisterChannel(name string, user *id.ID, messageType catalog.MessageType, newListener chan Message) ListenerID
RegisterChannel Registers a new listener built around the passed channel. Returns the ID of the new listener. Keep this around if you want to be able to delete the listener later.
name is used for debug printing and not checked for uniqueness
user: 0 for all, or any user ID to listen for messages from a particular user. 0 can be id.ZeroUser or id.ZeroID messageType: 0 for all, or any message type to listen for messages of that type. 0 can be Message.AnyType newListener: an item channel. Do not pass nil to this.
If a message matches multiple listeners, all of them will hear the message.
func (*Switchboard) RegisterFunc ¶
func (sw *Switchboard) RegisterFunc(name string, user *id.ID, messageType catalog.MessageType, newListener ListenerFunc) ListenerID
RegisterFunc Registers a new listener built around the passed function. Returns the ID of the new listener. Keep this around if you want to be able to delete the listener later.
name is used for debug printing and not checked for uniqueness
user: 0 for all, or any user ID to listen for messages from a particular user. 0 can be id.ZeroUser or id.ZeroID messageType: 0 for all, or any message type to listen for messages of that type. 0 can be Message.AnyType newListener: a function implementing the ListenerFunc function type. Do not pass nil to this.
If a message matches multiple listeners, all of them will hear the message.
func (*Switchboard) RegisterListener ¶
func (sw *Switchboard) RegisterListener(user *id.ID, messageType catalog.MessageType, newListener Listener) ListenerID
RegisterListener Registers a new listener. Returns the ID of the new listener. Keep this around if you want to be able to delete the listener later.
name is used for debug printing and not checked for uniqueness
user: 0 for all, or any user ID to listen for messages from a particular user. 0 can be id.ZeroUser or id.ZeroID messageType: 0 for all, or any message type to listen for messages of that type. 0 can be Message.AnyType newListener: something implementing the Listener interface. Do not pass nil to this.
If a message matches multiple listeners, all of them will hear the message.
func (*Switchboard) Speak ¶
func (sw *Switchboard) Speak(item Message)
Speak broadcasts a message to the appropriate listeners. each is spoken to in their own goroutine
func (*Switchboard) Unregister ¶
func (sw *Switchboard) Unregister(listenerID ListenerID)
Unregister removes the listener with the specified ID so it will no longer get called
func (*Switchboard) UnregisterUserListeners ¶
func (sw *Switchboard) UnregisterUserListeners(userID *id.ID)
UnregisterUserListeners removes all the listeners registered with the specified user.