--- AnyEvent/README 2008/05/26 06:04:38 1.23 +++ AnyEvent/README 2008/05/29 03:46:04 1.24 @@ -48,7 +48,7 @@ AnyEvent is different: AnyEvent + POE works fine. AnyEvent + Glib works fine. AnyEvent + Tk works fine etc. etc. but none of these work together - with the rest: POE + IO::Async? no go. Tk + Event? no go. Again: if your + with the rest: POE + IO::Async? No go. Tk + Event? No go. Again: if your module uses one of those, every user of your module has to use it, too. But if your module uses AnyEvent, it works transparently with all event models it supports (including stuff like POE and IO::Async, as long as @@ -62,7 +62,13 @@ only offering the functionality that is necessary, in as thin as a wrapper as technically possible. - Of course, if you want lots of policy (this can arguably be somewhat + Of course, AnyEvent comes with a big (and fully optional!) toolbox of + useful functionality, such as an asynchronous DNS resolver, 100% + non-blocking connects (even with TLS/SSL, IPv6 and on broken platforms + such as Windows) and lots of real-world knowledge and workarounds for + platform bugs and differences. + + Now, if you *do want* lots of policy (this can arguably be somewhat useful) and you want to force your users to use the one and only event model, you should *not* use this module. @@ -101,7 +107,7 @@ The pure-perl implementation of AnyEvent is called "AnyEvent::Impl::Perl". Like other event modules you can load it - explicitly. + explicitly and enjoy the high availability of that event loop :) WATCHERS AnyEvent has the central concept of a *watcher*, which is an object that @@ -222,6 +228,68 @@ AnyEvent always prefers relative timers, if available, matching the AnyEvent API. + AnyEvent has two additional methods that return the "current time": + + AnyEvent->time + This returns the "current wallclock time" as a fractional number of + seconds since the Epoch (the same thing as "time" or + "Time::HiRes::time" return, and the result is guaranteed to be + compatible with those). + + It progresses independently of any event loop processing, i.e. each + call will check the system clock, which usually gets updated + frequently. + + AnyEvent->now + This also returns the "current wallclock time", but unlike "time", + above, this value might change only once per event loop iteration, + depending on the event loop (most return the same time as "time", + above). This is the time that AnyEvent's timers get scheduled + against. + + *In almost all cases (in all cases if you don't care), this is the + function to call when you want to know the current time.* + + This function is also often faster then "AnyEvent->time", and thus + the preferred method if you want some timestamp (for example, + AnyEvent::Handle uses this to update it's activity timeouts). + + The rest of this section is only of relevance if you try to be very + exact with your timing, you can skip it without bad conscience. + + For a practical example of when these times differ, consider + Event::Lib and EV and the following set-up: + + The event loop is running and has just invoked one of your callback + at time=500 (assume no other callbacks delay processing). In your + callback, you wait a second by executing "sleep 1" (blocking the + process for a second) and then (at time=501) you create a relative + timer that fires after three seconds. + + With Event::Lib, "AnyEvent->time" and "AnyEvent->now" will both + return 501, because that is the current time, and the timer will be + scheduled to fire at time=504 (501 + 3). + + With EV, "AnyEvent->time" returns 501 (as that is the current time), + but "AnyEvent->now" returns 500, as that is the time the last event + processing phase started. With EV, your timer gets scheduled to run + at time=503 (500 + 3). + + In one sense, Event::Lib is more exact, as it uses the current time + regardless of any delays introduced by event processing. However, + most callbacks do not expect large delays in processing, so this + causes a higher drift (and a lot more system calls to get the + current time). + + In another sense, EV is more exact, as your timer will be scheduled + at the same time, regardless of how long event processing actually + took. + + In either case, if you care (and in most cases, you don't), then you + can get whatever behaviour you want with any event loop, by taking + the difference between "AnyEvent->time" and "AnyEvent->now" into + account. + SIGNAL WATCHERS You can watch for signals using a signal watcher, "signal" is the signal *name* without any "SIG" prefix, "cb" is the Perl callback to be invoked @@ -778,6 +846,10 @@ Setting this variable to 1 will cause AnyEvent::DNS to announce EDNS0 in its DNS requests. + "PERL_ANYEVENT_MAX_FORKS" + The maximum number of child processes that + "AnyEvent::Util::fork_call" will create in parallel. + EXAMPLE PROGRAM The following program uses an I/O watcher to read data from STDIN, a timer to display a message once per second, and a condition variable to