in reply to Call function no more than every 0.1 seconds
If you don't need to be almost precise, something like this might be good enough:
On my machine, it shows:#! /usr/bin/perl use warnings; use strict; use feature qw{ say }; use Time::HiRes qw{ time sleep }; sub func { sleep rand 0.05 } my $t0 = 0; while (1) { if (time - $t0 >= 0.1) { say $t0 = time; func(); } }
1597188470.0211 1597188470.1211 1597188470.2211 1597188470.3211 1597188470.4211 1597188470.52111 1597188470.62111 1597188470.72111 1597188470.82111 1597188470.92111 1597188471.02111 1597188471.12111 1597188471.22112 1597188471.32112 1597188471.42112 1597188471.52112 1597188471.62112 1597188471.72112 1597188471.82113
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
| A reply falls below the community's threshold of quality. You may see it by logging in. |