Closed CHTJonas closed 3 years ago
I think I prefer to stick to the defer Stop() method. Having to maintain stops on all function exits is fragile.
How about a single function which makes all the necessary Stop()
calls? I could factor this out into a separate PR if necessary (and maybe merge with parts of #116 minus the error bit)?
It's not the number of function calls, it's the fact that you need to make sure they're all there at any exit from the function. This is why defer is used.
Updated to use the defer-style syntax which I think looks better. It's objectively less code to worry about/forget in that select clause. I've also included the idempotent pinger.Stop()
because it made sense to.
This also fixes #157.
Yep correct on all accounts @sparrc!
In my opinion, there is no guarantee order in select
clause.
This PR:
Run()
function so that we always deal with received packets first rather than sending new packet out. This is so that the TTL values don't go stale when pinging very rapidly (cf. #154).Stop()
on tickers where possible.