add comments

This commit is contained in:
raziman 2021-02-19 22:22:24 +08:00
parent 1f0e990e2a
commit af336e1a60

View File

@ -4,10 +4,12 @@ type EventHook struct {
events map[string][]func()
}
// NewNewEventHook returns new instance of EventHook
func NewEventHook() *EventHook {
return &EventHook{make(map[string][]func())}
}
// AddHook accepts a function which will be executed when the event is emitted.
func (e *EventHook) AddHook(eventName string, handler func()) {
hooks, ok := e.events[eventName]
@ -19,6 +21,7 @@ func (e *EventHook) AddHook(eventName string, handler func()) {
e.events[eventName] = append(hooks, handler)
}
// RunHooks executes all hooks installed for an event.
func (e *EventHook) RunHooks(eventName string) {
hooks, ok := e.events[eventName]