broadcast

package module
v0.0.0-...-9d7fb01 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2014 License: BSD-3-Clause Imports: 1 Imported by: 12

README

broadcast

This package implements multi-listener broadcast channels for the Go programming language.

Install with go get github.com/tjgq/broadcast.

Browse the package documentation at http://godoc.org/github.com/tjgq/broadcast.

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.

type Listener

type Listener struct {
	// Ch receives the broadcast messages.
	Ch <-chan interface{}
	// contains filtered or unexported fields
}

Listener implements a listening endpoint for a broadcast channel.

func (*Listener) Close

func (l *Listener) Close()

Close closes the Listener, disabling the receival of further messages.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL