summaryrefslogtreecommitdiff
path: root/irc
diff options
context:
space:
mode:
authorHubert Hirtz <hubert@hirtz.pm>2021-11-16 09:20:21 +0100
committerHubert Hirtz <hubert@hirtz.pm>2021-11-16 22:22:10 +0100
commitd40d8dc36a608a1349f8353c50c2c71649e6fa75 (patch)
treed43e01ac710680c5e765e4726ff8928ec2431499 /irc
parentDon't merge message bounds from multiple networks (diff)
Allow App.Close() and App.Run() to be run concurrently
Diffstat (limited to 'irc')
-rw-r--r--irc/session.go1
-rw-r--r--irc/typing.go17
2 files changed, 15 insertions, 3 deletions
diff --git a/irc/session.go b/irc/session.go
index 084c6a7..07df816 100644
--- a/irc/session.go
+++ b/irc/session.go
@@ -170,6 +170,7 @@ func (s *Session) Close() {
return
}
s.closed = true
+ s.typings.Close()
close(s.out)
}
diff --git a/irc/typing.go b/irc/typing.go
index fd1576c..4a8cf55 100644
--- a/irc/typing.go
+++ b/irc/typing.go
@@ -16,6 +16,7 @@ type Typing struct {
// Typings keeps track of typing notification timeouts.
type Typings struct {
l sync.Mutex
+ closed bool // whether Close has been called
targets map[Typing]time.Time // @+typing TAGMSG timestamps.
timeouts chan Typing // transmits unfiltered timeout notifications.
stops chan Typing // transmits filtered timeout notifications.
@@ -45,10 +46,14 @@ func NewTypings() *Typings {
return ts
}
-// Stop cleanly closes all channels and stops all coroutines.
-func (ts *Typings) Stop() {
+// Close cleanly closes all channels and stops all goroutines.
+func (ts *Typings) Close() {
+ ts.l.Lock()
+ defer ts.l.Unlock()
+
close(ts.timeouts)
close(ts.stops)
+ ts.closed = true
}
// Stops is a channel that transmits typing timeouts.
@@ -65,7 +70,13 @@ func (ts *Typings) Active(target, name string) {
go func() {
time.Sleep(6 * time.Second)
- ts.timeouts <- t
+
+ ts.l.Lock()
+ defer ts.l.Unlock()
+
+ if !ts.closed {
+ ts.timeouts <- t
+ }
}()
}