26 lines
515 B
Go
26 lines
515 B
Go
package event
|
|
|
|
//type ResType int
|
|
|
|
type Events struct {
|
|
events map[Type][]func(arg ...interface{})
|
|
}
|
|
|
|
func NewEvents() *Events {
|
|
return &Events{events: make(map[Type][]func(arg ...interface{}))}
|
|
}
|
|
|
|
func (e *Events) EventRegister(eventType Type, event func(...interface{})) {
|
|
e.events[eventType] = append(e.events[eventType], event)
|
|
}
|
|
|
|
func (e *Events) Trigger(eventType Type, args ...interface{}) {
|
|
if cbs, ok := e.events[eventType]; ok {
|
|
for _, cb := range cbs {
|
|
if cb != nil {
|
|
cb(args)
|
|
}
|
|
}
|
|
}
|
|
}
|