/go-pubsub

Package pubsub is a simple publish-subscribe implementation using generics.

Primary LanguageGoMIT LicenseMIT

go-pubsub

PkgGoDev

Package pubsub is a simple publish-subscribe implementation using generics.

Example

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)
}

License

MIT