Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/robinbraemer/event
A stable Go event library to subscribe and fire events used to decouple the event source and sink in reactive add-on based systems. Generics supported!
https://github.com/robinbraemer/event
event golang library subscribe
Last synced: 27 days ago
JSON representation
A stable Go event library to subscribe and fire events used to decouple the event source and sink in reactive add-on based systems. Generics supported!
- Host: GitHub
- URL: https://github.com/robinbraemer/event
- Owner: robinbraemer
- License: mit
- Created: 2022-11-12T14:24:48.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-06T16:54:59.000Z (3 months ago)
- Last Synced: 2024-08-06T19:59:58.842Z (3 months ago)
- Topics: event, golang, library, subscribe
- Language: Go
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# event
Go event library to subscribe and fire events used to decouple the event
source and sink in complex or add-on based systems.```go
// Custom event type
type MyEvent struct {
Message string
}// Create a new event manager.
mgr := New()// Subscribe to the event.
Subscribe(mgr, 0, func(e *MyEvent) {
// Handle the event.
fmt.Println("handler A received event:", e.Message)
})// Subscribe to the event higher priority.
Subscribe(mgr, 1, func(e *MyEvent) {
// Handle the event.
fmt.Println("handler B received event:", e.Message)
e.Message = "hello gophers"
})unsubscribe := Subscribe(mgr, 0, func(e *MyEvent) {
// Handle the event.
fmt.Println("handler C received event:", e.Message)
})
// Unsubscribe from the event if you want to or ignore and never call it.
unsubscribe()// Fire the event.
mgr.Fire(&MyEvent{Message: "hello world"})
```## Used by
- [Gate](https://github.com/minekube/gate)