Documentation ¶
Overview ¶
Package pubsub provides extremely lightweight primitives for Publisher/Subscribe communication between goroutines. It allows creation of Pub/Sub groups and hierarchical topics.
Example ¶
var ps PubSub go func() { for { ps.Publish("topic1", "test") time.Sleep(1 * time.Second) } }() go func() { for { ps.Publish("topic2", "example") time.Sleep(2 * time.Second) } }() ch := ps.Subscribe("topic1.subtopic") for i := 0; i < 10; i++ { msg := <-ch fmt.Println("topic1.subtopic", msg) } ps.Unsubscribe(ch)
Output:
Index ¶
Examples ¶
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 group of Publishers and Subscribers.
func (*PubSub) Subscribe ¶
Subscribe allows for subscription to a specific topic. It returns a channel that can be used to get the messages from the topic specified. A topic can be a subtopic of another. E.g.
ps.Subscribe("topic1.subtopic")
receives also the messages from topic1.
func (*PubSub) Unsubscribe ¶
func (ps *PubSub) Unsubscribe(channel chan interface{})
Unsubscribe allows for the removal of a subscriber's channel. It requires a channel created with Subscribe.
Click to show internal directories.
Click to hide internal directories.