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

Comparing AnyEvent/lib/AnyEvent.pm (file contents):
Revision 1.83 by root, Fri Apr 25 13:39:08 2008 UTC vs.
Revision 1.84 by root, Fri Apr 25 13:48:42 2008 UTC

148creates a watcher waiting for "r"eadable or "w"ritable events, 148creates a watcher waiting for "r"eadable or "w"ritable events,
149respectively. C<cb> is the callback to invoke each time the file handle 149respectively. C<cb> is the callback to invoke each time the file handle
150becomes ready. 150becomes ready.
151 151
152The I/O watcher might use the underlying file descriptor or a copy of it. 152The I/O watcher might use the underlying file descriptor or a copy of it.
153It is not allowed to close a file handle as long as any watcher is active 153You must not close a file handle as long as any watcher is active on the
154on the underlying file descriptor. 154underlying file descriptor.
155 155
156Some event loops issue spurious readyness notifications, so you should 156Some event loops issue spurious readyness notifications, so you should
157always use non-blocking calls when reading/writing from/to your file 157always use non-blocking calls when reading/writing from/to your file
158handles. 158handles.
159
160Although the callback might get passed parameters, their value and
161presence is undefined and you cannot rely on them. Portable AnyEvent
162callbacks cannot use arguments passed to I/O watcher callbacks.
159 163
160Example: 164Example:
161 165
162 # wait for readability of STDIN, then read a line and disable the watcher 166 # wait for readability of STDIN, then read a line and disable the watcher
163 my $w; $w = AnyEvent->io (fh => \*STDIN, poll => 'r', cb => sub { 167 my $w; $w = AnyEvent->io (fh => \*STDIN, poll => 'r', cb => sub {
176case. 180case.
177 181
178The timer callback will be invoked at most once: if you want a repeating 182The timer callback will be invoked at most once: if you want a repeating
179timer you have to create a new watcher (this is a limitation by both Tk 183timer you have to create a new watcher (this is a limitation by both Tk
180and Glib). 184and Glib).
185
186Although the callback might get passed parameters, their value and
187presence is undefined and you cannot rely on them. Portable AnyEvent
188callbacks cannot use arguments passed to time watcher callbacks.
181 189
182Example: 190Example:
183 191
184 # fire an event after 7.7 seconds 192 # fire an event after 7.7 seconds
185 my $w = AnyEvent->timer (after => 7.7, cb => sub { 193 my $w = AnyEvent->timer (after => 7.7, cb => sub {
946file descriptors grows high. In this benchmark, all events become ready at 954file descriptors grows high. In this benchmark, all events become ready at
947the same time, so select/poll-based implementations get an unnatural speed 955the same time, so select/poll-based implementations get an unnatural speed
948boost. 956boost.
949 957
950C<EV> is the sole leader regarding speed and memory use, which are both 958C<EV> is the sole leader regarding speed and memory use, which are both
951maximal/minimal, respectively. Even when going through AnyEvent, there are 959maximal/minimal, respectively. Even when going through AnyEvent, it uses
952only two event loops that use slightly less memory (the C<Event> module 960far less memory than any other event loop and is still faster than Event
953natively and the pure perl backend), and no faster event models, not even 961natively.
954C<Event> natively.
955 962
956The pure perl implementation is hit in a few sweet spots (both the 963The pure perl implementation is hit in a few sweet spots (both the
957zero timeout and the use of a single fd hit optimisations in the perl 964zero timeout and the use of a single fd hit optimisations in the perl
958interpreter and the backend itself, and all watchers become ready at the 965interpreter and the backend itself, and all watchers become ready at the
959same time). Nevertheless this shows that it adds very little overhead in 966same time). Nevertheless this shows that it adds very little overhead in

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines