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.1 by root, Thu Jul 30 03:41:56 2009 UTC vs.
Revision 1.3 by root, Sun Aug 9 16:11:05 2009 UTC

2 2
3AE - simpler/faster/newer/cooler AnyEvent API 3AE - simpler/faster/newer/cooler AnyEvent API
4 4
5=head1 SYNOPSIS 5=head1 SYNOPSIS
6 6
7See the L<AnyEvent> manpage for everything there is to say about AE. 7 use AnyEvent; # not AE
8 8
9=head1 DESCRIPTION 9=head1 DESCRIPTION
10 10
11This module implements the new simpler AnyEvent API. There is no 11This module documents the new simpler AnyEvent API.
12description of this API here, refer to the L<AnyEvent> module for this.
13 12
14The rationale for the new API is that experience with L<EV> shows that 13The rationale for the new API is that experience with L<EV> shows that
15this API actually "works", despite it's simplicity. This API is (will be) 14this API actually "works", despite it's lack of extensibility, leading to
16much faster and also requires less typing. 15a shorter, easier and faster API.
17 16
18The "old" API is still supported, and there are no plans to "switch". 17The main difference to AnyEvent is that instead of method calls, function
18calls are used, and that no named arguments are used.
19
20This makes calls to watcher creation functions really short, which can
21make a program more readable, despite the lack of named parameters.
22Function calls also allow more static type checking than method calls, so
23many mistakes are caught at compiletime with this API.
24
25Also, some backends (Perl and EV) are so fast that the method call
26overhead is very noticable (with EV it increases the time five- to
27six-fold, with Perl the method call overhead is about a factor of two).
28
29At 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
31still.
32
33Note 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
35no plans to "switch", so if in doubt, use the L<AnyEvent> API.
36
37As 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,
39you should not C<use AE> directly, C<use AnyEvent> will provide the AE
40namespace.
41
42=head2 FUNCTIONS
43
44This section briefly describes the alternative watcher
45constructors. Semantics and any methods are not described here, please
46refer to the L<AnyEvent> manpage for the details.
47
48=over 4
19 49
20=cut 50=cut
21 51
22package AE; 52package AE;
23 53
24use AnyEvent (); # BEGIN { AnyEvent::common_sense } 54use AnyEvent (); # BEGIN { AnyEvent::common_sense }
25 55
261; 56=item $w = AE::io $fh_or_fd, $watch_write, $cb
57
58Creates 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
60file descriptor C<$fh_or_fd>.
61
62The callback C<$cb> is invoked as soon and as long as I/O of the type
63specified by C<$watch_write>) can be done on the file handle/descriptor.
64
65Example: wait until STDIN becomes readable.
66
67 $stdin_ready = AE::io *STDIN, 0, sub { scalar <STDIN> };
68
69Example. wait until STDOUT becomes writable and print something.
70
71 $stdout_ready = AE::io *STDOUT, 1, sub { print STDOUT "woaw\n" };
72
73=item $w = AE::timer $after, $interval, $cb
74
75Creates a timer watcher that invokes the callback C<$cb> after at least
76C<$after> second have passed (C<$after> can be negative or C<0>).
77
78If C<$interval> is C<0>, then the clalback will only be invoked once,
79otherwise it must be a positive number of seconds that specified the
80interval between successive invocations of the callback.
81
82Example: print "too late" after at least one second has passed.
83
84 $timer_once = AE::timer 1, 0, sub { print "too late\n" };
85
86Example: print "blubb" once a second, starting as soon as possible.
87
88 $timer_repeated = AE::timer 0, 1, sub { print "blubb\n" };
89
90=item $w = AE::signal $signame, $cb
91
92Invoke the callback c<$cb> each time one or more occurences of the named
93signal C<$signame> are detected.
94
95=item $w = AE::child $pid, $cb
96
97Invokes the callbakc C<$cb> when the child with the given C<$pid> exits
98(or all children, when C<$pid> is zero).
99
100The callback will get the actual pid and exit status as arguments.
101
102=item $w = AE::idle $cb
103
104Invoke the callback C<$cb> each time the event loop is "idle" (has no
105events outstanding), but do not prevent the event loop from polling for
106more events.
107
108=item $cv = AE::cv
109
110=item $cv = AE::cv { BLOCK }
111
112Create a new condition variable. The first form is identical to C<<
113AnyEvent->condvar >>, the second form additionally sets the callback (as
114if the C<cb> method is called on the condition variable).
115
116=item AE::now
117
118Returns the current event loop time (may be cached by the event loop).
119
120=item AE::now_update
121
122Ensures that the current event loop time is up to date.
123
124=item AE::time
125
126Return the current time (not cached, always consults a hardware clock).
127
128=back
27 129
28=head1 AUTHOR 130=head1 AUTHOR
29 131
30 Marc Lehmann <schmorp@schmorp.de> 132 Marc Lehmann <schmorp@schmorp.de>
31 http://home.schmorp.de/ 133 http://home.schmorp.de/
32 134
33=cut 135=cut
34 136
1371
138

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines