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

Comparing EV/EV.pm (file contents):
Revision 1.145 by root, Sat Jan 24 19:37:46 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.18'; 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,
614in front of the machine while the timer is running and changes the system 614in front of the machine while the timer is running and changes the system
615clock, the timer will nevertheless run (roughly) the same time. 615clock, the timer will nevertheless run (roughly) the same time.
616 616
617The C<timer_ns> variant doesn't start (activate) the newly created watcher. 617The C<timer_ns> variant doesn't start (activate) the newly created watcher.
618 618
619=item $w->set ($after, $repeat) 619=item $w->set ($after, $repeat = 0)
620 620
621Reconfigures the watcher, see the constructor above for details. Can be called at 621Reconfigures the watcher, see the constructor above for details. Can be called at
622any time. 622any time.
623 623
624=item $w->again 624=item $w->again
625
626=item $w->again ($repeat)
625 627
626Similar to the C<start> method, but has special semantics for repeating timers: 628Similar to the C<start> method, but has special semantics for repeating timers:
627 629
628If the timer is active and non-repeating, it will be stopped. 630If the timer is active and non-repeating, it will be stopped.
629 631
636 638
637This behaviour is useful when you have a timeout for some IO 639This behaviour is useful when you have a timeout for some IO
638operation. You create a timer object with the same value for C<$after> and 640operation. You create a timer object with the same value for C<$after> and
639C<$repeat>, and then, in the read/write watcher, run the C<again> method 641C<$repeat>, and then, in the read/write watcher, run the C<again> method
640on the timeout. 642on the timeout.
643
644If called with a C<$repeat> argument, then it uses this a timer repeat
645value.
646
647=item $after = $w->remaining
648
649Calculates and returns the remaining time till the timer will fire.
641 650
642=back 651=back
643 652
644 653
645=head3 PERIODIC WATCHERS - to cron or not to cron? 654=head3 PERIODIC WATCHERS - to cron or not to cron?
673surpasses this time. 682surpasses this time.
674 683
675=item * repeating interval timer ($interval > 0, $reschedule_cb = 0) 684=item * repeating interval timer ($interval > 0, $reschedule_cb = 0)
676 685
677In 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
678next 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,
679regardless 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>.
680 690
681This 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
682time: 692time:
683 693
684 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" };
708(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
709argument). It will usually be called just before the callback will be 719argument). It will usually be called just before the callback will be
710triggered, but might be called at other times, too. 720triggered, but might be called at other times, too.
711 721
712This 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
713triggers on each midnight, local time (actually 24 hours after the last 723triggers on each midnight, local time (actually one day after the last
714midnight, to keep the example simple. If you know a way to do it correctly 724midnight, to keep the example simple):
715in about the same space (without requiring elaborate modules), drop me a
716note :):
717 725
718 my $daily = EV::periodic 0, 0, sub { 726 my $daily = EV::periodic 0, 0, sub {
719 my ($w, $now) = @_; 727 my ($w, $now) = @_;
720 728
721 use Time::Local (); 729 use Time::Local ();
722 my (undef, undef, undef, $d, $m, $y) = localtime $now; 730 my (undef, undef, undef, $d, $m, $y) = localtime $now;
723 86400 + Time::Local::timelocal 0, 0, 0, $d, $m, $y 731 Time::Local::timelocal_nocheck 0, 0, 0, $d + 1, $m, $y
724 }, sub { 732 }, sub {
725 print "it's midnight or likely shortly after, now\n"; 733 print "it's midnight or likely shortly after, now\n";
726 }; 734 };
727 735
728=back 736=back

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines