… | |
… | |
119 | package EV; |
119 | package EV; |
120 | |
120 | |
121 | use common::sense; |
121 | use common::sense; |
122 | |
122 | |
123 | BEGIN { |
123 | BEGIN { |
124 | our $VERSION = 4.22; |
124 | our $VERSION = 4.25; |
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 | |
… | |
… | |
342 | | EV::WRITE>, indicating the type of I/O event you want to wait for. If |
342 | | EV::WRITE>, indicating the type of I/O event you want to wait for. If |
343 | you do not want to wait for some I/O event, specify C<undef> for |
343 | you do not want to wait for some I/O event, specify C<undef> for |
344 | C<$fh_or_undef> and C<0> for C<$events>). |
344 | C<$fh_or_undef> and C<0> for C<$events>). |
345 | |
345 | |
346 | If timeout is C<undef> or negative, then there will be no |
346 | If timeout is C<undef> or negative, then there will be no |
347 | timeout. Otherwise a EV::timer with this value will be started. |
347 | timeout. Otherwise an C<EV::timer> with this value will be started. |
348 | |
348 | |
349 | When an error occurs or either the timeout or I/O watcher triggers, then |
349 | When an error occurs or either the timeout or I/O watcher triggers, then |
350 | the callback will be called with the received event set (in general |
350 | the callback will be called with the received event set (in general |
351 | you can expect it to be a combination of C<EV::ERROR>, C<EV::READ>, |
351 | you can expect it to be a combination of C<EV::ERROR>, C<EV::READ>, |
352 | C<EV::WRITE> and C<EV::TIMER>). |
352 | C<EV::WRITE> and C<EV::TIMER>). |
… | |
… | |
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 | |
603 | Calls the callback after C<$after> seconds (which may be fractional). If |
603 | Calls the callback after C<$after> seconds (which may be fractional or |
604 | C<$repeat> is non-zero, the timer will be restarted (with the $repeat |
604 | negative). If C<$repeat> is non-zero, the timer will be restarted (with |
605 | value as $after) after the callback returns. |
605 | the $repeat value as $after) after the callback returns. |
606 | |
606 | |
607 | This means that the callback would be called roughly after C<$after> |
607 | This means that the callback would be called roughly after C<$after> |
608 | seconds, and then every C<$repeat> seconds. The timer does his best not |
608 | seconds, and then every C<$repeat> seconds. The timer does his best not |
609 | to drift, but it will not invoke the timer more often then once per event |
609 | to drift, but it will not invoke the timer more often then once per event |
610 | loop iteration, and might drift in other cases. If that isn't acceptable, |
610 | loop iteration, and might drift in other cases. If that isn't acceptable, |
… | |
… | |
682 | surpasses this time. |
682 | surpasses 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 | |
686 | In this mode the watcher will always be scheduled to time out at the |
686 | In this mode the watcher will always be scheduled to time out at the |
687 | next C<$at + N * $interval> time (for some integer N) and then repeat, |
687 | next C<$at + N * $interval> time (for the lowest integer N) and then repeat, |
688 | regardless of any time jumps. |
688 | regardless of any time jumps. Note that, since C<N> can be negative, the |
|
|
689 | first trigger can happen before C<$at>. |
689 | |
690 | |
690 | This can be used to create timers that do not drift with respect to system |
691 | This can be used to create timers that do not drift with respect to system |
691 | time: |
692 | time: |
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" }; |
… | |
… | |
709 | time as second argument. |
710 | time as second argument. |
710 | |
711 | |
711 | I<This callback MUST NOT stop or destroy this or any other periodic |
712 | I<This callback MUST NOT stop or destroy this or any other periodic |
712 | watcher, ever, and MUST NOT call any event loop functions or methods>. If |
713 | watcher, ever, and MUST NOT call any event loop functions or methods>. If |
713 | you need to stop it, return 1e30 and stop it afterwards. You may create |
714 | you need to stop it, return 1e30 and stop it afterwards. You may create |
714 | and start a C<EV::prepare> watcher for this task. |
715 | and start an C<EV::prepare> watcher for this task. |
715 | |
716 | |
716 | It must return the next time to trigger, based on the passed time value |
717 | It must return the next time to trigger, based on the passed time value |
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 |
718 | argument). It will usually be called just before the callback will be |
719 | argument). It will usually be called just before the callback will be |
719 | triggered, but might be called at other times, too. |
720 | triggered, but might be called at other times, too. |
720 | |
721 | |
721 | This can be used to create very complex timers, such as a timer that |
722 | This can be used to create very complex timers, such as a timer that |
722 | triggers on each midnight, local time (actually 24 hours after the last |
723 | triggers on each midnight, local time (actually one day after the last |
723 | midnight, to keep the example simple. If you know a way to do it correctly |
724 | midnight, to keep the example simple): |
724 | in about the same space (without requiring elaborate modules), drop me a |
|
|
725 | note :): |
|
|
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 |