1AE(3)                 User Contributed Perl Documentation                AE(3)
2
3
4

NAME

6       AE - simpler/faster/newer/cooler AnyEvent API
7

SYNOPSIS

9         use AnyEvent; # not AE
10
11         # file handle or descriptor readable
12         my $w = AE::io $fh, 0, sub { ...  };
13
14         # one-shot or repeating timers
15         my $w = AE::timer $seconds,         0, sub { ... }; # once
16         my $w = AE::timer $seconds, $interval, sub { ... }; # repeated
17
18         print AE::now;  # prints current event loop time
19         print AE::time; # think Time::HiRes::time or simply CORE::time.
20
21         # POSIX signal
22         my $w = AE::signal TERM => sub { ... };
23
24         # child process exit
25         my $w = AE::child $pid, sub {
26            my ($pid, $status) = @_;
27            ...
28         };
29
30         # called when event loop idle (if applicable)
31         my $w = AE::idle sub { ... };
32
33         my $cv = AE::cv; # stores whether a condition was flagged
34         $cv->send; # wake up current and all future recv's
35         $cv->recv; # enters "main loop" till $condvar gets ->send
36         # use a condvar in callback mode:
37         $cv->cb (sub { $_[0]->recv });
38

DESCRIPTION

40       This module documents the new simpler AnyEvent API.
41
42       The rationale for the new API is that experience with EV shows that
43       this API actually "works", despite its lack of extensibility, leading
44       to a shorter, easier and faster API.
45
46       The main differences from AnyEvent is that function calls are used
47       instead of method calls, and that no named arguments are used.
48
49       This makes calls to watcher creation functions really short, which can
50       make a program more readable despite the lack of named parameters.
51       Function calls also allow more static type checking than method calls,
52       so many mistakes are caught at compile-time with this API.
53
54       Also, some backends (Perl and EV) are so fast that the method call
55       overhead is very noticeable (with EV it increases the execution time
56       five- to six-fold, with Perl the method call overhead is about a factor
57       of two).
58
59       Note that the "AE" API is an alternative to, not the future version of,
60       the AnyEvent API. Both APIs can be used interchangeably and there are
61       no plans to "switch", so if in doubt, feel free to use the AnyEvent API
62       in new code.
63
64       As the AE API is complementary, not everything in the AnyEvent API is
65       available, and you still need to use AnyEvent for the finer stuff.
66       Also, you should not "use AE" directly, "use AnyEvent" will provide the
67       AE namespace.
68
69       At the moment, these functions will become slower then their method-
70       call counterparts when using AnyEvent::Strict or AnyEvent::Debug::wrap.
71
72   FUNCTIONS
73       This section briefly describes the alternative watcher constructors and
74       other functions available inside the "AE" namespace. Semantics are not
75       described here; please refer to the description of the function or
76       method with the same name in the AnyEvent manpage for the details.
77
78       $w = AE::io $fh_or_fd, $watch_write, $cb
79           Creates an I/O watcher that listens for read events ($watch_write
80           false) or write events ($watch_write is true) on the file handle or
81           file descriptor $fh_or_fd.
82
83           The callback $cb is invoked as soon and as long as I/O of the type
84           specified by $watch_write) can be done on the file
85           handle/descriptor.
86
87           Example: wait until STDIN becomes readable.
88
89             $stdin_ready = AE::io *STDIN, 0, sub { scalar <STDIN> };
90
91           Example: wait until STDOUT becomes writable and print something.
92
93             $stdout_ready = AE::io *STDOUT, 1, sub { print STDOUT "woaw\n" };
94
95       $w = AE::timer $after, $interval, $cb
96           Creates a timer watcher that invokes the callback $cb after at
97           least $after second have passed ($after can be negative or 0).
98
99           If $interval is 0, then the callback will only be invoked once,
100           otherwise it must be a positive number of seconds that specifies
101           the interval between successive invocations of the callback.
102
103           Example: print "too late" after at least one second has passed.
104
105             $timer_once = AE::timer 1, 0, sub { print "too late\n" };
106
107           Example: print "blubb" once a second, starting as soon as possible.
108
109             $timer_repeated = AE::timer 0, 1, sub { print "blubb\n" };
110
111       $w = AE::signal $signame, $cb
112           Invoke the callback $cb each time one or more occurrences of the
113           named signal $signame are detected.
114
115       $w = AE::child $pid, $cb
116           Invokes the callback $cb when the child with the given $pid exits
117           (or all children, when $pid is zero).
118
119           The callback will get the actual pid and exit status as arguments.
120
121       $w = AE::idle $cb
122           Invoke the callback $cb each time the event loop is "idle" (has no
123           events outstanding), but do not prevent the event loop from polling
124           for more events.
125
126       $cv = AE::cv
127       $cv = AE::cv { BLOCK }
128           Create a new condition variable. The first form is identical to
129           "AnyEvent->condvar", the second form additionally sets the callback
130           (as if the "cb" method is called on the condition variable).
131
132       AE::now
133           Returns the current event loop time (may be cached by the event
134           loop).
135
136       AE::now_update
137           Ensures that the current event loop time is up to date.
138
139       AE::time
140           Return the current time (not cached, always consults a hardware
141           clock).
142
143       AE::postpone { BLOCK }
144           Exactly the same as "AnyEvent:::postpone".
145
146       AE::log $level, $msg[, @args]
147           Exactly the same as "AnyEvent::log" (or "AnyEvent::Log::log").
148

AUTHOR

150        Marc Lehmann <schmorp@schmorp.de>
151        http://anyevent.schmorp.de
152
153
154
155perl v5.28.0                      2012-04-08                             AE(3)
Impressum