Added ClearCallback method for clearing all callbacks for an event
This commit is contained in:
parent
6edb7ec06e
commit
bf01c6c9e2
@ -40,6 +40,18 @@ func (irc *Connection) RemoveCallback(eventcode string, i string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (irc *Connection) ClearCallback(eventcode string) bool {
|
||||
eventcode = strings.ToUpper(eventcode)
|
||||
|
||||
if _, ok := irc.events[eventcode]; ok{
|
||||
irc.events[eventcode] = make(map[string]func(*Event))
|
||||
return true
|
||||
}
|
||||
|
||||
irc.Log.Println("Event not found")
|
||||
return false
|
||||
}
|
||||
|
||||
func (irc *Connection) ReplaceCallback(eventcode string, i string, callback func(*Event)) {
|
||||
eventcode = strings.ToUpper(eventcode)
|
||||
|
||||
|
26
irc_test.go
26
irc_test.go
@ -94,3 +94,29 @@ func TestWildcardCallback(t *testing.T) {
|
||||
t.Error("Wildcard callback not called")
|
||||
}
|
||||
}
|
||||
|
||||
func TestClearCallback(t *testing.T) {
|
||||
irccon := IRC("go-eventirc", "go-eventirc")
|
||||
irccon.VerboseCallbackHandler = true
|
||||
|
||||
done := make(chan int, 10)
|
||||
|
||||
irccon.AddCallback("TEST", func(e *Event) { done <- 0 })
|
||||
irccon.AddCallback("TEST", func(e *Event) { done <- 1 })
|
||||
irccon.ClearCallback("TEST")
|
||||
irccon.AddCallback("TEST", func(e *Event) { done <- 2 })
|
||||
irccon.AddCallback("TEST", func(e *Event) { done <- 3 })
|
||||
|
||||
irccon.RunCallbacks(&Event{
|
||||
Code: "TEST",
|
||||
})
|
||||
|
||||
var results []int
|
||||
|
||||
results = append(results, <-done)
|
||||
results = append(results, <-done)
|
||||
|
||||
if len(results) != 2 || !(results[0] == 2 && results[1] == 3) {
|
||||
t.Error("Callbacks not cleared")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user