Documentation
¶
Overview ¶
Package broadcast implements multi-listener broadcast channels.
To create an unbuffered broadcast channel, just declare a Broadcaster:
var b broadcaster.Broadcaster
To create a buffered broadcast channel with capacity n, call New:
b := broadcaster.New(n)
To add a listener to a channel, call Listen and read from Ch:
l := b.Listen() for v := range l.Ch { // ... }
To send to the channel, call Send:
b.Send("Hello world!") v <- l.Ch // returns interface{}("Hello world!")
To remove a listener, call Close.
l.Close()
To close the broadcast channel, call Close. Any existing or future listeners will read from a closed channel:
b.Close() v, ok <- l.Ch // returns ok == false
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Broadcaster ¶
type Broadcaster struct {
// contains filtered or unexported fields
}
Broadcaster implements a broadcast channel. The zero value is a usable unbuffered channel.
func New ¶
func New(n int) *Broadcaster
New returns a new Broadcaster with the given capacity (0 means unbuffered).
func (*Broadcaster) Close ¶
func (b *Broadcaster) Close()
Close closes the channel, disabling the sending of further messages.
func (*Broadcaster) Listen ¶
func (b *Broadcaster) Listen() *Listener
Listen returns a Listener for the broadcast channel.
func (*Broadcaster) Send ¶
func (b *Broadcaster) Send(v interface{})
Send broadcasts a message to the channel. Sending on a closed channel causes a runtime panic.