mirror of https://github.com/fluffle/goirc
gofix weekly fixes for event.
This commit is contained in:
parent
3710f67670
commit
0dc19703ab
|
@ -3,8 +3,8 @@ package event
|
||||||
import (
|
import (
|
||||||
"container/list"
|
"container/list"
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
)
|
)
|
||||||
|
|
||||||
type HandlerID uint32
|
type HandlerID uint32
|
||||||
|
@ -67,7 +67,8 @@ func (r *registry) AddHandler(h Handler, names ...string) {
|
||||||
}
|
}
|
||||||
r.Lock()
|
r.Lock()
|
||||||
defer r.Unlock()
|
defer r.Unlock()
|
||||||
N: for _, name := range names {
|
N:
|
||||||
|
for _, name := range names {
|
||||||
name = strings.ToLower(name)
|
name = strings.ToLower(name)
|
||||||
if _, ok := r.events[name]; !ok {
|
if _, ok := r.events[name]; !ok {
|
||||||
r.events[name] = list.New()
|
r.events[name] = list.New()
|
||||||
|
@ -97,7 +98,7 @@ func (r *registry) DelHandler(h Handler, names ...string) {
|
||||||
if len(names) == 0 {
|
if len(names) == 0 {
|
||||||
for name, l := range r.events {
|
for name, l := range r.events {
|
||||||
if _del(l, h.Id()) {
|
if _del(l, h.Id()) {
|
||||||
r.events[name] = nil, false
|
delete(r.events, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -105,7 +106,7 @@ func (r *registry) DelHandler(h Handler, names ...string) {
|
||||||
name = strings.ToLower(name)
|
name = strings.ToLower(name)
|
||||||
if l, ok := r.events[name]; ok {
|
if l, ok := r.events[name]; ok {
|
||||||
if _del(l, h.Id()) {
|
if _del(l, h.Id()) {
|
||||||
r.events[name] = nil, false
|
delete(r.events, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,7 +123,7 @@ func (r *registry) ClearEvents(name string) {
|
||||||
defer r.Unlock()
|
defer r.Unlock()
|
||||||
if l, ok := r.events[name]; ok {
|
if l, ok := r.events[name]; ok {
|
||||||
l.Init() // I hope this is enough to GC all list elements.
|
l.Init() // I hope this is enough to GC all list elements.
|
||||||
r.events[name] = nil, false
|
delete(r.events, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue