File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -272,9 +272,20 @@ func (t *HashBot) ReconnectClient() error {
272272func (t * HashBot ) ConnectClient (login string , token string ) error {
273273 var err error
274274
275+ ErrDisconnectTimeout := errors .New ("disconnect timed out" )
276+
275277 if t .TwitchClient != nil {
276- err = t .TwitchClient .Disconnect ()
277- if ! errors .Is (err , twitch .ErrConnectionIsNotOpen ) {
278+ result := make (chan error , 1 )
279+ go func () {
280+ result <- t .TwitchClient .Disconnect ()
281+ }()
282+ select {
283+ case err = <- result :
284+ case <- time .After (time .Second * 5 ):
285+ err = ErrDisconnectTimeout
286+ }
287+
288+ if ! errors .Is (err , twitch .ErrConnectionIsNotOpen ) && ! errors .Is (err , ErrDisconnectTimeout ) {
278289 return err
279290 }
280291 }
Original file line number Diff line number Diff line change 55 "context"
66 "encoding/json"
77 "errors"
8- flag "github.com/spf13/pflag"
98 "hashbot/backend"
109 "hashbot/command"
1110 "hashbot/config"
@@ -17,6 +16,8 @@ import (
1716 "sort"
1817 "time"
1918
19+ flag "github.com/spf13/pflag"
20+
2021 "github.com/gempir/go-twitch-irc/v4"
2122 "github.com/rs/zerolog"
2223 "github.com/rs/zerolog/log"
You can’t perform that action at this time.
0 commit comments