From 389025c95dbd5470e02cda6ced8a35ad74b3c257 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Thu, 8 Feb 2024 09:22:42 -0500 Subject: return pointer from Broadcast constructor --- broadcast.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'broadcast.go') diff --git a/broadcast.go b/broadcast.go index 7268971..9ad47f9 100644 --- a/broadcast.go +++ b/broadcast.go @@ -13,15 +13,15 @@ type Broadcast[T any] struct { // The caller is responsible for closing source. When source is closed, // Broadcast will close all destinations. -func NewBroadcast[T any](source chan T) Broadcast[T] { - bc := Broadcast[T]{ +func NewBroadcast[T any](source chan T) *Broadcast[T] { + bc := &Broadcast[T]{ source, make([]chan<- T, 0), sync.Mutex{}, sync.WaitGroup{}, } - go func(bc *Broadcast[T]) { + go func() { bc.wg.Add(1) for v := range bc.source { @@ -39,7 +39,7 @@ func NewBroadcast[T any](source chan T) Broadcast[T] { bc.mu.Unlock() bc.wg.Done() - }(&bc) + }() return bc } -- cgit v1.2.3