This package provides an implementation of the fan-out pattern.
Sending on a channel in Go normally results in a single channel receiving the value, even if multiple goroutines are receiving on the channel. Instead, this package provides Broadcaster, which multiple goroutines can Subscribe() to and receive copies of data Sent():
import "github.com/nitroshare/gobroadcast"
// Create the broadcaster
b := gobroadcast.New[int]()
// Subscribe to the broadcasts (returns a channel that receives them)
c := b.Subscribe()
// Broadcast values
b.Send(0)
b.Send(50)
b.Send(100)
// Unsubscribe from broadcasts
b.Unsubscribe(c)
// Shut down broadcaster (implicitly closing the channel for all subscribers)
b.Close()