@ -53,7 +53,7 @@ func (b *BroadcastString) AddListener(c chan string) chan string {
b.mu.Lock()
defer b.mu.Unlock()
if c == nil {
c = make(chan string, 0)
c = make(chan string, 4)
}
b.writers[c] = true
return c
@ -3,11 +3,13 @@ package main
import (
"sync"
"testing"
"time"
)
func TestBroadcast(t *testing.T) {
bs := NewBroadcastString()
bs.WriteMessage("hello")
time.Sleep(10 * time.Millisecond)
c1 := bs.AddListener(nil)
go func() {
bs.WriteMessage("world")