eclipse-paho / paho.mqtt.golang

Other
2.77k stars 534 forks source link

Replace the time.After with the timer for efficiency. #671

Closed DVasselli closed 7 months ago

DVasselli commented 7 months ago

The old time.After was not stopping the internal timer creating a huge resource overhead for frequently publishing clients. This way we stop the timer in the defer increasing efficiency.

Signed-off-by: Daniele Vasselli vasselli.daniele@gmail.com

MattBrittan commented 7 months ago

Thanks for the change; however this will deadlock if the timer does fire example. As the timer is not reused there is no real need to drain the channel.

DVasselli commented 7 months ago

Ohhh I totally misunderstood the documentation of t.Stop(). I pushed it without the drain nd we'll let the GC take care of the channel after return

MattBrittan commented 7 months ago

You are not the first person to do so. Thanks for the PR.

DVasselli commented 7 months ago

Happy to have learned something new! Any chance you can make a new tag for this so I can import it?

MattBrittan commented 7 months ago

Sorry - not going to do a new release for every small change. Just get the package with go get /github.com/eclipse/paho.mqtt.golang@master and you should get a version with the PR included.