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

Comparing AnyEvent/lib/AnyEvent.pm (file contents):
Revision 1.143 by root, Wed May 28 23:57:38 2008 UTC vs.
Revision 1.144 by root, Thu May 29 00:14:35 2008 UTC

243 243
244This returns the "current wallclock time" as a fractional number of 244This returns the "current wallclock time" as a fractional number of
245seconds since the Epoch (the same thing as C<time> or C<Time::HiRes::time> 245seconds since the Epoch (the same thing as C<time> or C<Time::HiRes::time>
246return, and the result is guaranteed to be compatible with those). 246return, and the result is guaranteed to be compatible with those).
247 247
248It progresses independently of any event loop processing. 248It progresses independently of any event loop processing, i.e. each call
249 249will check the system clock, which usually gets updated frequently.
250In almost all cases (in all cases if you don't care), this is the function
251to call when you want to know the current time.
252 250
253=item AnyEvent->now 251=item AnyEvent->now
254 252
255This also returns the "current wallclock time", but unlike C<time>, above, 253This also returns the "current wallclock time", but unlike C<time>, above,
256this value might change only once per event loop iteration, depending on 254this value might change only once per event loop iteration, depending on
257the event loop (most return the same time as C<time>, above). This is the 255the event loop (most return the same time as C<time>, above). This is the
258time that AnyEvent timers get scheduled against. 256time that AnyEvent's timers get scheduled against.
257
258I<In almost all cases (in all cases if you don't care), this is the
259function to call when you want to know the current time.>
260
261This function is also often faster then C<< AnyEvent->time >>, and
262thus the preferred method if you want some timestamp (for example,
263L<AnyEvent::Handle> uses this to update it's activity timeouts).
264
265The rest of this section is only of relevance if you try to be very exact
266with your timing, you can skip it without bad conscience.
259 267
260For a practical example of when these times differ, consider L<Event::Lib> 268For a practical example of when these times differ, consider L<Event::Lib>
261and L<EV> and the following set-up: 269and L<EV> and the following set-up:
262 270
263The event loop is running and has just invoked one of your callback at 271The event loop is running and has just invoked one of your callback at
268 276
269With L<Event::Lib>, C<< AnyEvent->time >> and C<< AnyEvent->now >> will 277With L<Event::Lib>, C<< AnyEvent->time >> and C<< AnyEvent->now >> will
270both return C<501>, because that is the current time, and the timer will 278both return C<501>, because that is the current time, and the timer will
271be scheduled to fire at time=504 (C<501> + C<3>). 279be scheduled to fire at time=504 (C<501> + C<3>).
272 280
273With L<EV>m C<< AnyEvent->time >> returns C<501> (as that is the current 281With L<EV>, C<< AnyEvent->time >> returns C<501> (as that is the current
274time), but C<< AnyEvent->now >> returns C<500>, as that is the time the 282time), but C<< AnyEvent->now >> returns C<500>, as that is the time the
275last event processing phase started. With L<EV>, your timer gets scheduled 283last event processing phase started. With L<EV>, your timer gets scheduled
276to run at time=503 (C<500> + C<3>). 284to run at time=503 (C<500> + C<3>).
277 285
278In one sense, L<Event::Lib> is more exact, as it uses the current time 286In one sense, L<Event::Lib> is more exact, as it uses the current time
279regardless of any delays introduced by event processing. However, most 287regardless of any delays introduced by event processing. However, most
280callbacks do not expect large delays in processing, so this causes a 288callbacks do not expect large delays in processing, so this causes a
281higher drift (and a lot more syscalls to get the current time). 289higher drift (and a lot more system calls to get the current time).
282 290
283In another sense, L<EV> is more exact, as your timer will be scheduled at 291In another sense, L<EV> is more exact, as your timer will be scheduled at
284the same time, regardless of how long event processing actually took. 292the same time, regardless of how long event processing actually took.
285 293
286In either case, if you care (and in most cases, you don't), then you 294In either case, if you care (and in most cases, you don't), then you

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines