… | |
… | |
48 | the beginning of 1970, details are complicated, don't ask). This type is |
48 | the beginning of 1970, details are complicated, don't ask). This type is |
49 | called C<ev_tstamp>, which is what you should use too. It usually aliases |
49 | called C<ev_tstamp>, which is what you should use too. It usually aliases |
50 | to the double type in C. |
50 | to the double type in C. |
51 | |
51 | |
52 | =head1 GLOBAL FUNCTIONS |
52 | =head1 GLOBAL FUNCTIONS |
|
|
53 | |
|
|
54 | These functions can be called anytime, even before initialising the |
|
|
55 | library in any way. |
53 | |
56 | |
54 | =over 4 |
57 | =over 4 |
55 | |
58 | |
56 | =item ev_tstamp ev_time () |
59 | =item ev_tstamp ev_time () |
57 | |
60 | |
… | |
… | |
560 | In this mode the values for C<interval> and C<at> are both being |
563 | In this mode the values for C<interval> and C<at> are both being |
561 | ignored. Instead, each time the periodic watcher gets scheduled, the |
564 | ignored. Instead, each time the periodic watcher gets scheduled, the |
562 | reschedule callback will be called with the watcher as first, and the |
565 | reschedule callback will be called with the watcher as first, and the |
563 | current time as second argument. |
566 | current time as second argument. |
564 | |
567 | |
565 | NOTE: I<This callback MUST NOT stop or destroy the periodic or any other |
568 | NOTE: I<This callback MUST NOT stop or destroy any periodic watcher, |
566 | periodic watcher, ever, or make any event loop modifications>. If you need |
569 | ever, or make any event loop modifications>. If you need to stop it, |
567 | to stop it, return C<now + 1e30> (or so, fudge fudge) and stop it afterwards. |
570 | return C<now + 1e30> (or so, fudge fudge) and stop it afterwards (e.g. by |
568 | |
571 | starting a prepare watcher). |
569 | Also, I<< this callback must always return a time that is later than the |
|
|
570 | passed C<now> value >>. Not even C<now> itself will be ok. |
|
|
571 | |
572 | |
572 | Its prototype is C<ev_tstamp (*reschedule_cb)(struct ev_periodic *w, |
573 | Its prototype is C<ev_tstamp (*reschedule_cb)(struct ev_periodic *w, |
573 | ev_tstamp now)>, e.g.: |
574 | ev_tstamp now)>, e.g.: |
574 | |
575 | |
575 | static ev_tstamp my_rescheduler (struct ev_periodic *w, ev_tstamp now) |
576 | static ev_tstamp my_rescheduler (struct ev_periodic *w, ev_tstamp now) |
… | |
… | |
579 | |
580 | |
580 | It must return the next time to trigger, based on the passed time value |
581 | It must return the next time to trigger, based on the passed time value |
581 | (that is, the lowest time value larger than to the second argument). It |
582 | (that is, the lowest time value larger than to the second argument). It |
582 | will usually be called just before the callback will be triggered, but |
583 | will usually be called just before the callback will be triggered, but |
583 | might be called at other times, too. |
584 | might be called at other times, too. |
|
|
585 | |
|
|
586 | NOTE: I<< This callback must always return a time that is later than the |
|
|
587 | passed C<now> value >>. Not even C<now> itself will do, it must be larger. |
584 | |
588 | |
585 | This can be used to create very complex timers, such as a timer that |
589 | This can be used to create very complex timers, such as a timer that |
586 | triggers on each midnight, local time. To do this, you would calculate the |
590 | triggers on each midnight, local time. To do this, you would calculate the |
587 | next midnight after C<now> and return the timestamp value for this. How you do this |
591 | next midnight after C<now> and return the timestamp value for this. How you do this |
588 | is, again, up to you (but it is not trivial). |
592 | is, again, up to you (but it is not trivial). |