diff --git a/broadcast.go b/broadcast.go index 367840a..e690ce6 100644 --- a/broadcast.go +++ b/broadcast.go @@ -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 diff --git a/broadcast_test.go b/broadcast_test.go index 8ae2f85..2a4a60b 100644 --- a/broadcast_test.go +++ b/broadcast_test.go @@ -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")