Documentation ¶
Overview ¶
Package topic provides a publish-subscribe mechanism where consumers may disappear at any time.
Each Topic is exactly that, a single topic. There is no filtering of messages or such functionality on this level. For example, you could create a new Topic for each chat room on your chat server, with every browser instance using an WebSockets API to Register on every room the user wants to follow.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Topic ¶
type Topic struct { // Producer sends messages on this channel. Close the channel // to shutdown the topic. Broadcast chan<- interface{} // contains filtered or unexported fields }
Topic is a pub-sub mechanism where consumers can Register to receive messages sent to Broadcast.
func New ¶
func New() *Topic
New creates a new topic. Messages can be broadcast on this topic, and registered consumers are guaranteed to either receive them, or see a channel close.
func (*Topic) Register ¶
func (t *Topic) Register(ch chan<- interface{})
Register starts receiving messages on the given channel. If a channel close is seen, either the topic has been shut down, or the consumer was too slow, and should re-register.
func (*Topic) Unregister ¶
func (t *Topic) Unregister(ch chan<- interface{})
Unregister stops receiving messages on this channel.