33 lines
483 B
Go
Raw Normal View History

2021-11-22 16:05:02 +00:00
package hub_test
import (
"fmt"
"github.com/cenk/hub"
)
// Different event kinds
const (
happenedA hub.Kind = iota
happenedB
happenedC
)
// Our custom event type
type EventA struct {
arg1, arg2 int
}
// Implement hub.Event interface
func (e EventA) Kind() hub.Kind { return happenedA }
func Example() {
hub.Subscribe(happenedA, func(e hub.Event) {
a := e.(EventA) // Cast to concrete type
fmt.Println(a.arg1 + a.arg2)
})
hub.Publish(EventA{2, 3})
// Output: 5
}