https://github.com/shomali11/eventbus
Eventbus
https://github.com/shomali11/eventbus
event eventbus publish subscribe
Last synced: 5 months ago
JSON representation
Eventbus
- Host: GitHub
- URL: https://github.com/shomali11/eventbus
- Owner: shomali11
- License: mit
- Created: 2017-08-06T03:00:48.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2019-06-08T15:08:53.000Z (over 6 years ago)
- Last Synced: 2025-04-13T03:49:07.560Z (6 months ago)
- Topics: event, eventbus, publish, subscribe
- Language: Go
- Size: 79.1 KB
- Stars: 6
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# eventbus [](https://travis-ci.com/shomali11/eventbus) [](https://goreportcard.com/report/github.com/shomali11/eventbus) [](https://godoc.org/github.com/shomali11/eventbus) [](https://opensource.org/licenses/MIT)
An event bus to facilitate publishing and subscribing to events via topics
## Features
* Non blocking publishing of events
## Dependencies
* `maps` [github.com/shomali11/maps](https://github.com/shomali11/maps)
# Examples
## Example 1
Using `NewClient` to create an eventbus.
```go
package mainimport "github.com/shomali11/eventbus"
func main() {
client := eventbus.NewClient()
defer client.Close()
}
```## Example 2
Using `Publish` and `Subscribe` to publish and listen to events
```go
package mainimport (
"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
```