in reply to Blocking call with time limit ( Linux::Inotify2 )

The simple solution is Time::HiRes:

use Time::HiRes qw[ time sleep ]; ... $inotify->blocking(0); my $end = time() + $timelimit; while( time() < $end ) { for my $event ( $inotify->read ) { ## process event. } sleep 0.01; ## or 0.001 per your latency requirements }

As for your fears about cpu usage. Polling once every hundredth or thousandth of a second, (much less every second), barely raises the usage at all. On my system, the usage is not discernible from zero to 2 decimal places.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP an inspiration; A true Folk's Guy