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