… | |
… | |
207 | |
207 | |
208 | There are two ways to handle timers: based on real time (relative, "fire |
208 | There are two ways to handle timers: based on real time (relative, "fire |
209 | in 10 seconds") and based on wallclock time (absolute, "fire at 12 |
209 | in 10 seconds") and based on wallclock time (absolute, "fire at 12 |
210 | o'clock"). |
210 | o'clock"). |
211 | |
211 | |
212 | While most event loops expect timers to specified in a relative way, they use |
212 | While most event loops expect timers to specified in a relative way, they |
213 | absolute time internally. This makes a difference when your clock "jumps", |
213 | use absolute time internally. This makes a difference when your clock |
214 | for example, when ntp decides to set your clock backwards from the wrong 2014-01-01 to |
214 | "jumps", for example, when ntp decides to set your clock backwards from |
215 | 2008-01-01, a watcher that you created to fire "after" a second might actually take |
215 | the wrong date of 2014-01-01 to 2008-01-01, a watcher that is supposed to |
216 | six years to finally fire. |
216 | fire "after" a second might actually take six years to finally fire. |
217 | |
217 | |
218 | AnyEvent cannot compensate for this. The only event loop that is conscious |
218 | AnyEvent cannot compensate for this. The only event loop that is conscious |
219 | about these issues is L<EV>, which offers both relative (ev_timer) and |
219 | about these issues is L<EV>, which offers both relative (ev_timer, based |
220 | absolute (ev_periodic) timers. |
220 | on true relative time) and absolute (ev_periodic, based on wallclock time) |
|
|
221 | timers. |
221 | |
222 | |
222 | AnyEvent always prefers relative timers, if available, matching the |
223 | AnyEvent always prefers relative timers, if available, matching the |
223 | AnyEvent API. |
224 | AnyEvent API. |
224 | |
225 | |
225 | =head2 SIGNAL WATCHERS |
226 | =head2 SIGNAL WATCHERS |
226 | |
227 | |
227 | You can watch for signals using a signal watcher, C<signal> is the signal |
228 | You can watch for signals using a signal watcher, C<signal> is the signal |
228 | I<name> without any C<SIG> prefix, C<cb> is the Perl callback to |
229 | I<name> without any C<SIG> prefix, C<cb> is the Perl callback to |
229 | be invoked whenever a signal occurs. |
230 | be invoked whenever a signal occurs. |
230 | |
231 | |
231 | Multiple signals occurances can be clumped together into one callback |
232 | Multiple signal occurances can be clumped together into one callback |
232 | invocation, and callback invocation will be synchronous. synchronous means |
233 | invocation, and callback invocation will be synchronous. synchronous means |
233 | that it might take a while until the signal gets handled by the process, |
234 | that it might take a while until the signal gets handled by the process, |
234 | but it is guarenteed not to interrupt any other callbacks. |
235 | but it is guarenteed not to interrupt any other callbacks. |
235 | |
236 | |
236 | The main advantage of using these watchers is that you can share a signal |
237 | The main advantage of using these watchers is that you can share a signal |