Package pubsub is a simple publish-subscribe implementation using generics.
ctx := context.Background()
topic := pubsub.NewTopic[int](ctx)
ch := make(chan int)
topic.Subscribe(ctx, ch)
go func() {
defer topic.Close()
for i := range 3 {
topic.Publish(ctx, i)
}
}()
for i := range ch {
fmt.Println(i)
}
MIT