NAME

Time::HiRes::Sleep::Until - Provides common ways to sleep until...

SYNOPSIS

use Time::HiRes::Sleep::Until;
my $su=Time::HiRes::Sleep::Until->new;
$su->epoch(1420070400.0);       # sleep until 2015-01-01 00:00
$su->mark(20);                  # sleep until 20 second mark of the clock :00, :20, or :40
$su->second(45);                # sleep until 45 seconds after the minute

DESCRIPTION

Sleep Until provides sleep wrappers for common sleep functions that I typically need. These methods are simply wrappers around Time::HiRes and Math::Round.

We use this package to make measurements at the same time within the minute for integration with RRDtool.

USAGE

use strict;
use warnings;
use DateTime;
use Time::HiRes::Sleep::Until;
my $su=Time::HiRes::Sleep::Until->new;
do {
  print DateTime->now, "\n"; #make a measurment three times a minute
} while ($su->mark(20));

Perl One liner

perl -MTime::HiRes::Sleep::Until -e 'printf "Slept: %s\n", Time::HiRes::Sleep::Until->new->top'

CONSTRUCTOR

new

use Time::HiRes::Sleep::Until;
my $su=Time::HiRes::Sleep::Until->new;

METHODS

epoch

Sleep until provided epoch in float seconds.

my $slept=$su->epoch($epoch); #epoch is simply a calculated time + $seconds

mark

Sleep until next second mark;

my $slept=$su->mark(20); # 20 second mark, i.e.  3 times a minute on the 20s
my $slept=$su->mark(10); # 10 second mark, i.e.  6 times a minute on the 10s
my $slept=$su->mark(6);  #  6 second mark, i.e. 10 times a minute on 0,6,12,...

second

Sleep until the provided seconds after the minute

my $slept=$su->second(0);  #sleep until top of minute
my $slept=$su->second(30); #sleep until bottom of minute

top

Sleep until the top of the minute

my $slept=$su->top; #alias for $su->second(0);

LIMITATIONS

The mathematics add a small amount of delay for which we do not account. Testing routinely passes with 100th of a second accuracy and typically with millisecond accuracy.

BUGS

Please log on RT and send an email to the author.

SUPPORT

DavisNetworks.com supports all Perl applications including this package.

AUTHOR

Michael R. Davis
CPAN ID: MRDVT
Satellite Tracking of People, LLC
mdavis@stopllc.com
http://www.stopllc.com/

COPYRIGHT

This program is free software licensed under the...

The General Public License (GPL), Version 2, June 1991

The full text of the license can be found in the LICENSE file included with this module.

SEE ALSO

Time::HiRes, Math::Round