Skip to content

Commit 1a63b63

Browse files
authored
Merge pull request #671 from DVasselli/clientTimer
Replace the time.After with the timer for efficiency.
2 parents f21bdb1 + 8b638fb commit 1a63b63

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

client.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,9 +799,13 @@ func (c *client) Publish(topic string, qos byte, retained bool, payload interfac
799799
if publishWaitTimeout == 0 {
800800
publishWaitTimeout = time.Second * 30
801801
}
802+
803+
t := time.NewTimer(publishWaitTimeout)
804+
defer t.Stop()
805+
802806
select {
803807
case c.obound <- &PacketAndToken{p: pub, t: token}:
804-
case <-time.After(publishWaitTimeout):
808+
case <-t.C:
805809
token.setError(errors.New("publish was broken by timeout"))
806810
}
807811
}

0 commit comments

Comments
 (0)