irc: fix timer memleak

This is a gotcha called out in the `time.After` docs. `time.After` will
leak the underlying channel if nothing ever receives on it.
This commit is contained in:
Euan Kemp 2017-07-13 23:45:17 -07:00 committed by Daniel Oaks
parent b003cd6287
commit 2e8a98a925
1 changed files with 3 additions and 1 deletions

View File

@ -133,10 +133,12 @@ func (socket *Socket) Write(data string) error {
// timedFillLineToSendExists either sends the note or times out.
func (socket *Socket) timedFillLineToSendExists(duration time.Duration) {
lineToSendTimeout := time.NewTimer(duration)
defer lineToSendTimeout.Stop()
select {
case socket.lineToSendExists <- true:
// passed data successfully
case <-time.After(duration):
case <-lineToSendTimeout.C:
// timed out send
}
}