BREAKING CHANGES: Run callbacks in main thread and int callback id.

Execute callbacks in main thread. This will break callbacks that
use a long time to execute. Create your own thread in AddCallback
using gorutines on long running callbacks.

Use deterministic IDs for AddCallback. Changes the id from SHA-hash
to int.
This commit is contained in:
Thomas Jager
2016-02-06 21:33:04 +01:00
parent ab737c68eb
commit da78ed515c
4 changed files with 64 additions and 52 deletions

View File

@@ -184,33 +184,26 @@ func TestConnection(t *testing.T) {
irccon2 := IRC("go-eventirc2", "go-eventirc2")
irccon2.VerboseCallbackHandler = true
irccon2.Debug = true
err := irccon1.Connect("irc.freenode.net:6667")
if err != nil {
t.Log(err.Error())
t.Fatal("Can't connect to freenode.")
}
err = irccon2.Connect("irc.freenode.net:6667")
if err != nil {
t.Log(err.Error())
t.Fatal("Can't connect to freenode.")
}
irccon1.AddCallback("001", func(e *Event) { irccon1.Join("#go-eventirc") })
irccon2.AddCallback("001", func(e *Event) { irccon2.Join("#go-eventirc") })
con2ok := false
irccon1.AddCallback("366", func(e *Event) {
t := time.NewTicker(1 * time.Second)
i := 10
for {
<-t.C
irccon1.Privmsgf("#go-eventirc", "Test Message%d\n", i)
if con2ok {
i -= 1
go func(e *Event) {
t := time.NewTicker(1 * time.Second)
i := 10
for {
<-t.C
irccon1.Privmsgf("#go-eventirc", "Test Message%d\n", i)
if con2ok {
i -= 1
}
if i == 0 {
t.Stop()
irccon1.Quit()
}
}
if i == 0 {
t.Stop()
irccon1.Quit()
}
}
}(e)
})
irccon2.AddCallback("366", func(e *Event) {
@@ -231,6 +224,18 @@ func TestConnection(t *testing.T) {
t.Fatal("Nick change did not work!")
}
})
err := irccon1.Connect("irc.freenode.net:6667")
if err != nil {
t.Log(err.Error())
t.Fatal("Can't connect to freenode.")
}
err = irccon2.Connect("irc.freenode.net:6667")
if err != nil {
t.Log(err.Error())
t.Fatal("Can't connect to freenode.")
}
go irccon2.Loop()
irccon1.Loop()
}
@@ -241,11 +246,6 @@ func TestConnectionSSL(t *testing.T) {
irccon.Debug = true
irccon.UseTLS = true
irccon.TLSConfig = &tls.Config{InsecureSkipVerify: true}
err := irccon.Connect("irc.freenode.net:7000")
if err != nil {
t.Log(err.Error())
t.Fatal("Can't connect to freenode.")
}
irccon.AddCallback("001", func(e *Event) { irccon.Join("#go-eventirc") })
irccon.AddCallback("366", func(e *Event) {
@@ -254,5 +254,11 @@ func TestConnectionSSL(t *testing.T) {
irccon.Quit()
})
err := irccon.Connect("irc.freenode.net:7000")
if err != nil {
t.Log(err.Error())
t.Fatal("Can't connect to freenode.")
}
irccon.Loop()
}