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

Comparing AnyEvent/lib/AE.pm (file contents):
Revision 1.3 by root, Sun Aug 9 16:11:05 2009 UTC vs.
Revision 1.7 by root, Wed Mar 24 23:28:06 2010 UTC

3AE - simpler/faster/newer/cooler AnyEvent API 3AE - simpler/faster/newer/cooler AnyEvent API
4 4
5=head1 SYNOPSIS 5=head1 SYNOPSIS
6 6
7 use AnyEvent; # not AE 7 use AnyEvent; # not AE
8
9 # file handle or descriptor readable
10 my $w = AE::io $fh, 0, sub { ... };
11
12 # one-shot or repeating timers
13 my $w = AE::timer $seconds, 0, sub { ... }; # once
14 my $w = AE::timer $seconds, interval, sub { ... }; # repeated
15
16 print AE::now; # prints current event loop time
17 print AE::time; # think Time::HiRes::time or simply CORE::time.
18
19 # POSIX signal
20 my $w = AE::signal TERM => sub { ... };
21
22 # child process exit
23 my $w = AE::child $pid, sub {
24 my ($pid, $status) = @_;
25 ...
26 };
27
28 # called when event loop idle (if applicable)
29 my $w = AE::idle { ... };
30
31 my $w = AE::cv; # stores whether a condition was flagged
32 $w->send; # wake up current and all future recv's
33 $w->recv; # enters "main loop" till $condvar gets ->send
34 # use a condvar in callback mode:
35 $w->cb (sub { $_[0]->recv });
36
8 37
9=head1 DESCRIPTION 38=head1 DESCRIPTION
10 39
11This module documents the new simpler AnyEvent API. 40This module documents the new simpler AnyEvent API.
12 41
21make a program more readable, despite the lack of named parameters. 50make a program more readable, despite the lack of named parameters.
22Function calls also allow more static type checking than method calls, so 51Function calls also allow more static type checking than method calls, so
23many mistakes are caught at compiletime with this API. 52many mistakes are caught at compiletime with this API.
24 53
25Also, some backends (Perl and EV) are so fast that the method call 54Also, some backends (Perl and EV) are so fast that the method call
26overhead is very noticable (with EV it increases the time five- to 55overhead is very noticeable (with EV it increases the execution time five-
27six-fold, with Perl the method call overhead is about a factor of two). 56to six-fold, with Perl the method call overhead is about a factor of two).
28 57
29At the moment, there will be no checking (L<AnyEvent::Strict> does not 58At the moment, there will be no checking (L<AnyEvent::Strict> does not
30affect his API), so the L<AnyEvent> API has a definite advantage here 59affect his API), so the L<AnyEvent> API has a definite advantage here
31still. 60still.
32 61
33Note that the C<AE> API is an alternative to, not the future version of, 62Note that the C<AE> API is an alternative to, not the future version of,
34the AnyEvent API. Both APIs can be used interchangably and and there are 63the AnyEvent API. Both APIs can be used interchangably and and there are
35no plans to "switch", so if in doubt, use the L<AnyEvent> API. 64no plans to "switch", so if in doubt, feel free to use the L<AnyEvent>
65API in new code.
36 66
37As the AE API is complementary, not everything in the AnyEvent API is 67As the AE API is complementary, not everything in the AnyEvent API is
38available, so you still need to use AnyEvent for the finer stuff. Also, 68available, so you still need to use AnyEvent for the finer stuff. Also,
39you should not C<use AE> directly, C<use AnyEvent> will provide the AE 69you should not C<use AE> directly, C<use AnyEvent> will provide the AE
40namespace. 70namespace.
50=cut 80=cut
51 81
52package AE; 82package AE;
53 83
54use AnyEvent (); # BEGIN { AnyEvent::common_sense } 84use AnyEvent (); # BEGIN { AnyEvent::common_sense }
85
86our $VERSION = $AnyEvent::VERSION;
55 87
56=item $w = AE::io $fh_or_fd, $watch_write, $cb 88=item $w = AE::io $fh_or_fd, $watch_write, $cb
57 89
58Creates an I/O watcher that listens for read events (C<$watch_write> 90Creates an I/O watcher that listens for read events (C<$watch_write>
59false) or write events (C<$watch_write> is true) on the file handle or 91false) or write events (C<$watch_write> is true) on the file handle or

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines