https://github.com/desertbit/event
A simple event emitter for Go
https://github.com/desertbit/event
Last synced: 6 months ago
JSON representation
A simple event emitter for Go
- Host: GitHub
- URL: https://github.com/desertbit/event
- Owner: desertbit
- License: mit
- Created: 2017-09-09T12:29:51.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-11T11:04:00.000Z (almost 9 years ago)
- Last Synced: 2025-08-15T03:50:01.949Z (11 months ago)
- Language: Go
- Size: 2.93 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Event - A simple event emitter for Go
[](https://godoc.org/github.com/desertbit/event)
[](https://goreportcard.com/report/github.com/desertbit/event)
This project was inspired by [the emission package](https://github.com/chuckpreslar/emission).
Instead of passing strings as event keys, I prefer to have one struct per event.
## Sample
```go
package main
import (
"fmt"
"github.com/desertbit/event"
)
func main() {
e := event.New()
e.On(onEvent)
e.Once(onceEvent)
e.TriggerWait("Hello World", 1)
e.TriggerWait("Hello World", 2)
e.Off(onEvent)
e.TriggerWait("Hello World", 3)
}
func onEvent(s string, i int) {
fmt.Println("on:", s, i)
}
func onceEvent(s string, i int) {
fmt.Println("once:", s, i)
}
```