Did you know that in 99% of applications and absolutely all CPAN modules, timers and timeouts are implemented incorrectly? Do not believe? Do not believe correctly! There is, there is
one CPAN-module, with the correct implementation of timers:
EV . :) (By the way, this seems to be the only CPAN module out of all that implement the event loop, which knows about the
problem of using fork with the event loop , describes it in the documentation, and even tries to solve it somehow!)
The problem is that to implement timers and timeouts, functions that return the current time are used. And the current time can be changed at any time in any direction to any value - by the administrator or the NTP daemon. Therefore, it turns out that, for example, the timeout set by the program for 30 seconds can work either after 2 seconds or after a couple of days - depending on how the current time changes after setting the timeout (and in especially neglected cases it may never work).
The only reliable way to work with timers and timeouts is to use
monotonous time:
use Time::HiRes qw( clock_gettime CLOCK_MONOTONIC );
$now = clock_gettime(CLOCK_MONOTONIC);
CLOCK_MONOTONIC support was added to Time :: HiRes (at my initiative :)) two years ago. And today I again, like two years ago,
looked for modules on CPAN with the correct implementation of timers and timeouts ... and found only one. :(