func (b *Broadcaster) Listen() *Listener {
	b.m.Lock()
	defer b.m.Unlock()
	if b.listeners == nil {
		b.listeners = make(map[uint]chan<- interface{})
	}
	if b.listeners[b.nextID] != nil {
		b.nextID++
	}
	ch := make(chan interface{}, b.capacity)
	if b.closed {
		close(ch)
	}
	b.listeners[b.nextID] = ch
	return &Listener{ch, b, b.nextID}
}
Listen returns a Listener for the broadcast channel.
package broadcast
import (
	"errors"
	"fmt"
	"sync"
	"time"
	"github.com/hashicorp/go-multierror"
)
const ErrClosedChannel = broadcastError("send after close")
type broadcastError string
func (e broadcastError) Error() string { return string(e) }
type Broadcaster struct {
	m         sync.Mutex
	listeners map[uint]chan<- interface{}  
	nextID    uint
	capacity  int
	closed    bool
}
func NewBroadcaster(n int) *Broadcaster {
	return &Broadcaster{capacity: n}
}
func (b *Broadcaster) SendWithTimeout(v interface{}, timeout time.Duration) error {
	b.m.Lock()
	defer b.m.Unlock()
	if b.closed {
		return ErrClosedChannel
	}
	var result *multierror.Error
	for id, l := range b.listeners {
		select {
		case l <- v:
		case <-time.After(timeout):
			err := fmt.Sprintf("unable to send to listener '%d'", id)
			result = multierror.Append(result, errors.New(err))
		}
	}
	if result != nil {
		return result.ErrorOrNil()
	} else {
		return nil
	}
}
func (b *Broadcaster) Send(v interface{}) error {
	return b.SendWithTimeout(v, 0)
}
func (b *Broadcaster) Discard() {
	b.m.Lock()
	defer b.m.Unlock()
	if b.closed {
		return
	}
	b.closed = true
	for _, l := range b.listeners {
		close(l)
	}
}