Skip to content
Snippets Groups Projects
Commit 9291dc9f authored by capossele's avatar capossele
Browse files

:bug: added RWMutex

parent 12c0145c
No related branches found
No related tags found
No related merge requests found
package events
import "sync"
type Event struct {
triggerFunc func(handler interface{}, params ...interface{})
callbacks map[uintptr]interface{}
mutex sync.RWMutex
}
func (this *Event) Attach(closure *Closure) {
this.mutex.Lock()
defer this.mutex.Unlock()
this.callbacks[closure.Id] = closure.Fnc
}
func (this *Event) Detach(closure *Closure) {
this.mutex.Lock()
defer this.mutex.Unlock()
delete(this.callbacks, closure.Id)
}
func (this *Event) Trigger(params ...interface{}) {
this.mutex.RLock()
defer this.mutex.RUnlock()
for _, handler := range this.callbacks {
this.triggerFunc(handler, params...)
}
......
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