sesopenko/genericpubsub
A lightweight, type-safe publish/subscribe system for Go, using generics and context-based cancellation
{ "createdAt": "2025-04-18T05:45:17Z", "defaultBranch": "main", "description": "A lightweight, type-safe publish/subscribe system for Go, using generics and context-based cancellation", "fullName": "sesopenko/genericpubsub", "homepage": null, "language": "Go", "name": "genericpubsub", "pushedAt": "2025-04-18T06:41:28Z", "stargazersCount": 18, "topics": [], "updatedAt": "2025-10-16T23:02:14Z", "url": "https://github.com/sesopenko/genericpubsub"}genericpubsub
Section titled “genericpubsub”genericpubsub is a lightweight, type-safe publish/subscribe system for Go, using generics and context-based
cancellation. It allows you to publish messages of any type to multiple subscribers concurrently, with clean shutdown
and resource management.
Features
Section titled “Features”- Type-safe using Go generics
- Simple API:
Send,Subscribe - Context-based cancellation
- Graceful shutdown of subscribers
- Fully tested with unit tests
Installation
Section titled “Installation”go get github.com/sesopenko/genericpubsubDocumentation
Section titled “Documentation”https://pkg.go.dev/github.com/sesopenko/genericpubsub
Example
Section titled “Example”package main
import ( "context" "fmt" "time" "github.com/sesopenko/genericpubsub")
type Message struct { Value string}
func main() { channelBuffer := 64 ps := genericpubsub.New[Message]!(context.Background(), channelBuffer) sub := ps.Subscribe(context.TODO(), channelBuffer)
go ps.Send(Message{Value: "hello"}) time.Sleep(50 * time.Millisecond) msg, ok := <-sub fmt.Println("Received:", msg.Value) fmt.Printf("channel wasn't closed: %t\n", ok)}License
Section titled “License”This project is licensed under the MIT license. See [LICENSE.txt]!(LICENSE.txt) for details.
© 2025 Sean Esopenko