diff --git a/packages/events/event.go b/packages/events/event.go index ae8de77f9963fa8801919c21a257086c752dc566..9bd6053386b7c9506c9c34b8613125de97f8797b 100644 --- a/packages/events/event.go +++ b/packages/events/event.go @@ -10,22 +10,22 @@ type Event struct { func (this *Event) Attach(closure *Closure) { this.mutex.Lock() - defer this.mutex.Unlock() this.callbacks[closure.Id] = closure.Fnc + this.mutex.Unlock() } func (this *Event) Detach(closure *Closure) { this.mutex.Lock() - defer this.mutex.Unlock() delete(this.callbacks, closure.Id) + this.mutex.Unlock() } func (this *Event) Trigger(params ...interface{}) { this.mutex.RLock() - defer this.mutex.RUnlock() for _, handler := range this.callbacks { this.triggerFunc(handler, params...) } + this.mutex.RUnlock() } func NewEvent(triggerFunc func(handler interface{}, params ...interface{})) *Event {