Skip to content

Commit

Permalink
Merge pull request #671 from DVasselli/clientTimer
Browse files Browse the repository at this point in the history
Replace the time.After with the timer for efficiency.
  • Loading branch information
MattBrittan authored Mar 21, 2024
2 parents f21bdb1 + 8b638fb commit 1a63b63
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -799,9 +799,13 @@ func (c *client) Publish(topic string, qos byte, retained bool, payload interfac
if publishWaitTimeout == 0 {
publishWaitTimeout = time.Second * 30
}

t := time.NewTimer(publishWaitTimeout)
defer t.Stop()

select {
case c.obound <- &PacketAndToken{p: pub, t: token}:
case <-time.After(publishWaitTimeout):
case <-t.C:
token.setError(errors.New("publish was broken by timeout"))
}
}
Expand Down

0 comments on commit 1a63b63

Please sign in to comment.