ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV/EV.pm
(Generate patch)

Comparing EV/EV.pm (file contents):
Revision 1.147 by root, Mon Jul 13 19:47:53 2015 UTC vs.
Revision 1.152 by root, Sun Oct 28 23:40:32 2018 UTC

119package EV; 119package EV;
120 120
121use common::sense; 121use common::sense;
122 122
123BEGIN { 123BEGIN {
124 our $VERSION = 4.21; 124 our $VERSION = 4.22;
125 use XSLoader; 125 use XSLoader;
126 local $^W = 0; # avoid spurious warning 126 local $^W = 0; # avoid spurious warning
127 XSLoader::load "EV", $VERSION; 127 XSLoader::load "EV", $VERSION;
128} 128}
129 129
296=item $active = EV::run [$flags] 296=item $active = EV::run [$flags]
297 297
298=item $active = $loop->run ([$flags]) 298=item $active = $loop->run ([$flags])
299 299
300Begin checking for events and calling callbacks. It returns when a 300Begin checking for events and calling callbacks. It returns when a
301callback calls EV::break or the flasg are nonzero (in which case the 301callback calls EV::break or the flags are nonzero (in which case the
302return value is true) or when there are no active watchers which reference 302return value is true) or when there are no active watchers which reference
303the loop (keepalive is true), in which case the return value will be 303the loop (keepalive is true), in which case the return value will be
304false. The returnv alue can generally be interpreted as "if true, there is 304false. The return value can generally be interpreted as "if true, there is
305more work left to do". 305more work left to do".
306 306
307The $flags argument can be one of the following: 307The $flags argument can be one of the following:
308 308
309 0 as above 309 0 as above
598 598
599=item $w = $loop->timer ($after, $repeat, $callback) 599=item $w = $loop->timer ($after, $repeat, $callback)
600 600
601=item $w = $loop->timer_ns ($after, $repeat, $callback) 601=item $w = $loop->timer_ns ($after, $repeat, $callback)
602 602
603Calls the callback after C<$after> seconds (which may be fractional). If 603Calls the callback after C<$after> seconds (which may be fractional or
604C<$repeat> is non-zero, the timer will be restarted (with the $repeat 604negative). If C<$repeat> is non-zero, the timer will be restarted (with
605value as $after) after the callback returns. 605the $repeat value as $after) after the callback returns.
606 606
607This means that the callback would be called roughly after C<$after> 607This means that the callback would be called roughly after C<$after>
608seconds, and then every C<$repeat> seconds. The timer does his best not 608seconds, and then every C<$repeat> seconds. The timer does his best not
609to drift, but it will not invoke the timer more often then once per event 609to drift, but it will not invoke the timer more often then once per event
610loop iteration, and might drift in other cases. If that isn't acceptable, 610loop iteration, and might drift in other cases. If that isn't acceptable,
682surpasses this time. 682surpasses this time.
683 683
684=item * repeating interval timer ($interval > 0, $reschedule_cb = 0) 684=item * repeating interval timer ($interval > 0, $reschedule_cb = 0)
685 685
686In this mode the watcher will always be scheduled to time out at the 686In this mode the watcher will always be scheduled to time out at the
687next C<$at + N * $interval> time (for some integer N) and then repeat, 687next C<$at + N * $interval> time (for the lowest integer N) and then repeat,
688regardless of any time jumps. 688regardless of any time jumps. Note that, since C<N> can be negative, the
689first trigger can happen before C<$at>.
689 690
690This can be used to create timers that do not drift with respect to system 691This can be used to create timers that do not drift with respect to system
691time: 692time:
692 693
693 my $hourly = EV::periodic 0, 3600, 0, sub { print "once/hour\n" }; 694 my $hourly = EV::periodic 0, 3600, 0, sub { print "once/hour\n" };
717(that is, the lowest time value larger than or equal to to the second 718(that is, the lowest time value larger than or equal to to the second
718argument). It will usually be called just before the callback will be 719argument). It will usually be called just before the callback will be
719triggered, but might be called at other times, too. 720triggered, but might be called at other times, too.
720 721
721This can be used to create very complex timers, such as a timer that 722This can be used to create very complex timers, such as a timer that
722triggers on each midnight, local time (actually 24 hours after the last 723triggers on each midnight, local time (actually one day after the last
723midnight, to keep the example simple. If you know a way to do it correctly 724midnight, to keep the example simple):
724in about the same space (without requiring elaborate modules), drop me a
725note :):
726 725
727 my $daily = EV::periodic 0, 0, sub { 726 my $daily = EV::periodic 0, 0, sub {
728 my ($w, $now) = @_; 727 my ($w, $now) = @_;
729 728
730 use Time::Local (); 729 use Time::Local ();
731 my (undef, undef, undef, $d, $m, $y) = localtime $now; 730 my (undef, undef, undef, $d, $m, $y) = localtime $now;
732 86400 + Time::Local::timelocal 0, 0, 0, $d, $m, $y 731 Time::Local::timelocal_nocheck 0, 0, 0, $d + 1, $m, $y
733 }, sub { 732 }, sub {
734 print "it's midnight or likely shortly after, now\n"; 733 print "it's midnight or likely shortly after, now\n";
735 }; 734 };
736 735
737=back 736=back

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines