From bdb5c9b1a068cc0554c5c989861ba8936f817614 Mon Sep 17 00:00:00 2001 From: Alex Bramley Date: Wed, 9 Nov 2011 21:14:24 +0000 Subject: [PATCH] Squash a couple of bugs found by the unit tests. --- event/registry.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/event/registry.go b/event/registry.go index 920c3f8..5984085 100644 --- a/event/registry.go +++ b/event/registry.go @@ -55,7 +55,7 @@ type registry struct { dispatcher func(r *registry, name string, ev ...interface{}) } -func NewRegistry() EventRegistry { +func NewRegistry() *registry { r := ®istry{events: make(map[string]*list.List)} r.Parallel() return r @@ -67,7 +67,7 @@ func (r *registry) AddHandler(h Handler, names ...string) { } r.Lock() defer r.Unlock() - for _, name := range names { +N: for _, name := range names { name = strings.ToLower(name) if _, ok := r.events[name]; !ok { r.events[name] = list.New() @@ -75,7 +75,7 @@ func (r *registry) AddHandler(h Handler, names ...string) { for e := r.events[name].Front(); e != nil; e = e.Next() { // Check we're not adding a duplicate handler to this event if e.Value.(Handler).Id() == h.Id() { - return + continue N } } r.events[name].PushBack(h) @@ -99,6 +99,7 @@ func (r *registry) DelHandler(h Handler, names ...string) { } } else { for _, name := range names { + name = strings.ToLower(name) if l, ok := r.events[name]; ok { _del(l, h.Id()) } @@ -107,13 +108,13 @@ func (r *registry) DelHandler(h Handler, names ...string) { } func (r *registry) Dispatch(name string, ev ...interface{}) { - r.dispatcher(r, name, ev...) + r.dispatcher(r, strings.ToLower(name), ev...) } func (r *registry) ClearEvents(name string) { r.Lock() defer r.Unlock() - if l, ok := r.events[name]; ok { + if l, ok := r.events[strings.ToLower(name)]; ok { l.Init() } } @@ -127,7 +128,6 @@ func (r *registry) Serial() { } func (r *registry) parallelDispatch(name string, ev ...interface{}) { - name = strings.ToLower(name) r.RLock() defer r.RUnlock() if l, ok := r.events[name]; ok { @@ -139,7 +139,6 @@ func (r *registry) parallelDispatch(name string, ev ...interface{}) { } func (r *registry) serialDispatch(name string, ev ...interface{}) { - name = strings.ToLower(name) r.RLock() defer r.RUnlock() if l, ok := r.events[name]; ok {