Lightweight generic events library for go
go get github.com/kmalaver/events
package main
import "github.com/kmalaver/events"
func main() {
// Create new event
e := events.New[string]()
// Subscribe to event
e.Subscribe(func(s string) {
fmt.Println(s)
})
// Dispatch event
e.Dispatch("Hello world!")
}
Subscribe(f func(payload T)) (unsubscribe func())
Dispatch(payload T)
SubscribeOnce(f func(payload T)) (unsubscribe func())
SubscribeAsync(f func(payload T)) (unsubscribe func())
SubscribeOnceAsync(f func(payload T)) (unsubscribe func())
Wait()