Documentation ¶
Overview ¶
Package pubsub implements a simple multi-topic pub-sub library.
Topics must be strings and messages of type Mailbox can be published. A topic can have any number of subcribers and all of them receive messages published on the topic.
Index ¶
- type Mailbox
- type Message
- type PubSub
- func (ps *PubSub) Close(topics ...string)
- func (ps *PubSub) CreateMailbox() chan *Mailbox
- func (ps *PubSub) Pub(msg *Message, topics ...string)
- func (ps *PubSub) Shutdown()
- func (ps *PubSub) Sub(ch chan *Mailbox, topics ...string)
- func (ps *PubSub) SubOnce(ch chan *Mailbox, topics ...string)
- func (ps *PubSub) Unsub(ch chan *Mailbox, topics ...string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PubSub ¶
type PubSub struct {
// contains filtered or unexported fields
}
PubSub is a collection of topics.
func New ¶
New creates a new PubSub and starts a goroutine for handling operations. The capacity of the channels created by Sub and SubOnce will be as specified.
func (*PubSub) Close ¶
Close closes all channels currently subscribed to the specified topics. If a channel is subscribed to multiple topics, some of which is not specified, it is not closed.
func (*PubSub) CreateMailbox ¶
CreateMailbox creates a channel that will be used to subscribe to and send messages to
func (*PubSub) Shutdown ¶
func (ps *PubSub) Shutdown()
Shutdown closes all subscribed channels and terminates the goroutine.