Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/twpayne/go-pubsub

Package pubsub is a simple publish-subscribe implementation using generics.
https://github.com/twpayne/go-pubsub

go golang publish-subscribe pubsub

Last synced: 2 months ago
JSON representation

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

Awesome Lists containing this project

README

        

# go-pubsub

[![PkgGoDev](https://pkg.go.dev/badge/github.com/twpayne/go-pubsub)](https://pkg.go.dev/github.com/twpayne/go-pubsub)

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

## Example

```go
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