1
0
Fork 0
mirror of https://github.com/fluffle/goirc synced 2025-07-02 11:33:54 +00:00

Make API for adding/deleting handlers more coherent.

Previously, it was possible to add the same handler (as returned by NewHandler)
to multiple different event lists, but DelHandler only removed a handler from
*all* event lists it was present in. This may not be wanted behaviour, and
reduces control over the event lists.

Instead, allow both Add and DelHandler to take a variadic list of events to
add or delete handlers from.
This commit is contained in:
Alex Bramley 2011-11-07 13:13:46 +00:00
parent 4853024928
commit 6e87169e2c
2 changed files with 37 additions and 21 deletions

View file

@ -14,7 +14,7 @@ func TestSimpleDispatch(t *testing.T) {
h := NewHandler(func(ev ...interface{}) {
out <- ev[0].(bool)
})
r.AddHandler("send", h)
r.AddHandler(h, "send")
r.Dispatch("send", true)
if val := <-out; !val {
@ -42,7 +42,7 @@ func TestParallelDispatch(t *testing.T) {
// create some handlers and send an event to them
for _, t := range []int{5, 11, 2, 15, 8} {
r.AddHandler("send", factory(t))
r.AddHandler(factory(t), "send")
}
r.Dispatch("send")
@ -80,7 +80,7 @@ func TestSerialDispatch(t *testing.T) {
// create some handlers and send an event to them
for _, t := range []int{5, 11, 2, 15, 8} {
r.AddHandler("send", factory(t))
r.AddHandler(factory(t), "send")
}
r.Dispatch("send")