Skip to content
Snippets Groups Projects
Commit 895dfc09 authored by capossele's avatar capossele
Browse files

:zap: improved mutex usage

parent 77c15bb8
No related branches found
No related tags found
No related merge requests found
......@@ -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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment