--- AnyEvent/lib/AE.pm 2009/08/09 15:09:28 1.2 +++ AnyEvent/lib/AE.pm 2010/03/24 23:28:06 1.7 @@ -6,12 +6,42 @@ use AnyEvent; # not AE + # file handle or descriptor readable + my $w = AE::io $fh, 0, sub { ... }; + + # one-shot or repeating timers + my $w = AE::timer $seconds, 0, sub { ... }; # once + my $w = AE::timer $seconds, interval, sub { ... }; # repeated + + print AE::now; # prints current event loop time + print AE::time; # think Time::HiRes::time or simply CORE::time. + + # POSIX signal + my $w = AE::signal TERM => sub { ... }; + + # child process exit + my $w = AE::child $pid, sub { + my ($pid, $status) = @_; + ... + }; + + # called when event loop idle (if applicable) + my $w = AE::idle { ... }; + + my $w = AE::cv; # stores whether a condition was flagged + $w->send; # wake up current and all future recv's + $w->recv; # enters "main loop" till $condvar gets ->send + # use a condvar in callback mode: + $w->cb (sub { $_[0]->recv }); + + =head1 DESCRIPTION This module documents the new simpler AnyEvent API. The rationale for the new API is that experience with L shows that -this API actually "works", despite it's lack of extensibility. +this API actually "works", despite it's lack of extensibility, leading to +a shorter, easier and faster API. The main difference to AnyEvent is that instead of method calls, function calls are used, and that no named arguments are used. @@ -22,8 +52,8 @@ many mistakes are caught at compiletime with this API. Also, some backends (Perl and EV) are so fast that the method call -overhead is very noticable (with EV it increases the time five- to -six-fold, with Perl the method call overhead is about a factor of two). +overhead is very noticeable (with EV it increases the execution time five- +to six-fold, with Perl the method call overhead is about a factor of two). At the moment, there will be no checking (L does not affect his API), so the L API has a definite advantage here @@ -31,7 +61,8 @@ Note that the C API is an alternative to, not the future version of, the AnyEvent API. Both APIs can be used interchangably and and there are -no plans to "switch", so if in doubt, use L's API. +no plans to "switch", so if in doubt, feel free to use the L +API in new code. As the AE API is complementary, not everything in the AnyEvent API is available, so you still need to use AnyEvent for the finer stuff. Also, @@ -52,6 +83,8 @@ use AnyEvent (); # BEGIN { AnyEvent::common_sense } +our $VERSION = $AnyEvent::VERSION; + =item $w = AE::io $fh_or_fd, $watch_write, $cb Creates an I/O watcher that listens for read events (C<$watch_write>