diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2024-02-08 09:22:42 -0500 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2024-02-08 09:22:42 -0500 |
| commit | 389025c95dbd5470e02cda6ced8a35ad74b3c257 (patch) | |
| tree | 8924919c8210c4adf449de8bc97a7ba4b7a79512 /broadcast.go | |
| parent | 6c00320bf2d41d2e7392deff03709bae6cb5c2fb (diff) | |
| download | volute-389025c95dbd5470e02cda6ced8a35ad74b3c257.zip | |
return pointer from Broadcast constructor
Diffstat (limited to 'broadcast.go')
| -rw-r--r-- | broadcast.go | 8 |
1 files changed, 4 insertions, 4 deletions
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 } |