A multi-producer multi-consumer generic event bus.
go get github.com/maddiesch/go-bus
import (
"github.com/maddiesch/go-bus"
)
func main() {
eventBus := bus.New[string]()
subscription, cancel := eventBus.Sink()
defer cancel()
go produceEvents(eventBus)
for event := range subscription {
switch event {
case "stop":
return
default:
fmt.Println(event)
}
}
}
func produceEvents(eventBus *bus.Bus[string]) {
eventBus.Publish("Hello, World!")
eventBus.Publish("stop")
}