summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--irc/states.go16
-rw-r--r--irc/typing.go8
2 files changed, 19 insertions, 5 deletions
diff --git a/irc/states.go b/irc/states.go
index 7722d20..dcfff1f 100644
--- a/irc/states.go
+++ b/irc/states.go
@@ -260,6 +260,7 @@ func (s *Session) Stop() {
close(s.acts)
close(s.evts)
close(s.msgs)
+ s.typings.Stop()
}
// Poll returns the event channel where incoming events are reported.
@@ -465,7 +466,10 @@ func (s *Session) run() {
var err error
select {
- case act := <-s.acts:
+ case act, ok := <-s.acts:
+ if !ok {
+ break
+ }
switch act := act.(type) {
case actionSendRaw:
err = s.sendRaw(act)
@@ -484,13 +488,19 @@ func (s *Session) run() {
case actionRequestHistory:
err = s.requestHistory(act)
}
- case msg := <-s.msgs:
+ case msg, ok := <-s.msgs:
+ if !ok {
+ break
+ }
if s.registered {
err = s.handle(msg)
} else {
err = s.handleStart(msg)
}
- case t := <-s.typings.Stops():
+ case t, ok := <-s.typings.Stops():
+ if !ok {
+ break
+ }
s.evts <- TagEvent{
User: s.users[t.Name].Name,
Target: s.channels[t.Target].Name,
diff --git a/irc/typing.go b/irc/typing.go
index a62a420..28fb223 100644
--- a/irc/typing.go
+++ b/irc/typing.go
@@ -24,8 +24,7 @@ func NewTypings() *Typings {
stops: make(chan Typing, 16),
}
go func() {
- for {
- t := <-ts.timeouts
+ for t := range ts.timeouts {
now := time.Now()
ts.l.Lock()
oldT, ok := ts.targets[t]
@@ -41,6 +40,11 @@ func NewTypings() *Typings {
return ts
}
+func (ts *Typings) Stop() {
+ close(ts.timeouts)
+ close(ts.stops)
+}
+
func (ts *Typings) Stops() <-chan Typing {
return ts.stops
}