An event bus to facilitate publishing and subscribing to events via topics
- Non blocking publishing of events
Using NewClient
to create an eventbus.
package main
import "github.com/shomali11/eventbus"
func main() {
client := eventbus.NewClient()
defer client.Close()
}
Using Publish
and Subscribe
to publish and listen to events
package main
import (
"fmt"
"github.com/shomali11/eventbus"
"time"
)
func main() {
client := eventbus.NewClient()
defer client.Close()
client.Publish("test", "test")
client.Subscribe("name", func(value interface{}) {
fmt.Println(value)
})
client.Subscribe("name", func(value interface{}) {
fmt.Println(value, "is Awesome")
})
client.Publish("name", "Raed Shomali")
time.Sleep(time.Second)
}
Output:
Raed Shomali
Raed Shomali is Awesome