Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event[K comparable, D any] struct { // contains filtered or unexported fields }
type EventHub ¶
type EventHub[K comparable, D any] struct { // contains filtered or unexported fields }
Example ¶
m := New[int, int]() fn1 := func(data int) { fmt.Println("1 call=", data) } fn2 := func(data int) { fmt.Println("2 call=", data) } fn3 := func(data int) { fmt.Println("3 call=", data) } fn4 := func(data int) { fmt.Println("4 call=", data) } m.On(1, fn1).On(2, fn2).On(3, fn3).On(4, fn4) m.Fire(1, 1) m.Fire(2, 2) m.Fire(3, 3) m.Fire(4, 4) m.Off(2, fn2).Off(3, fn3) m.Fire(1, 100) m.Fire(2, 200) m.Fire(3, 300) m.Fire(4, 400)
Output: 1 call= 1 2 call= 2 3 call= 3 4 call= 4 1 call= 100 4 call= 400
func (*EventHub[K, D]) Fire ¶
func (h *EventHub[K, D]) Fire(key K, data D) EventHuber[K, D]
func (*EventHub[K, D]) Off ¶
func (h *EventHub[K, D]) Off(key K, fn HandleFunc[D]) EventHuber[K, D]
func (*EventHub[K, D]) On ¶
func (h *EventHub[K, D]) On(key K, fn HandleFunc[D]) EventHuber[K, D]
type EventHuber ¶
type EventHuber[K comparable, D any] interface { On(key K, fn HandleFunc[D]) EventHuber[K, D] Off(key K, fn HandleFunc[D]) EventHuber[K, D] Fire(key K, data D) EventHuber[K, D] }
func New ¶
func New[K comparable, D any]() EventHuber[K, D]
type HandleFunc ¶
type HandleFunc[D any] func(data D)
Click to show internal directories.
Click to hide internal directories.