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.265 by root, Wed Jul 29 13:10:58 2009 UTC vs.
Revision 1.266 by root, Thu Jul 30 03:41:56 2009 UTC

181my variables are only visible after the statement in which they are 181my variables are only visible after the statement in which they are
182declared. 182declared.
183 183
184=head2 I/O WATCHERS 184=head2 I/O WATCHERS
185 185
186 $w = AnyEvent->io (
187 fh => <filehandle_or_fileno>,
188 poll => <"r" or "w">,
189 cb => <callback>,
190 );
191
186You can create an I/O watcher by calling the C<< AnyEvent->io >> method 192You can create an I/O watcher by calling the C<< AnyEvent->io >> method
187with the following mandatory key-value pairs as arguments: 193with the following mandatory key-value pairs as arguments:
188 194
189C<fh> is the Perl I<file handle> (or a naked file descriptor) to watch 195C<fh> is the Perl I<file handle> (or a naked file descriptor) to watch
190for events (AnyEvent might or might not keep a reference to this file 196for events (AnyEvent might or might not keep a reference to this file
219 undef $w; 225 undef $w;
220 }); 226 });
221 227
222=head2 TIME WATCHERS 228=head2 TIME WATCHERS
223 229
230 $w = AnyEvent->timer (after => <seconds>, cb => <callback>);
231
232 $w = AnyEvent->timer (
233 after => <fractional_seconds>,
234 interval => <fractional_seconds>,
235 cb => <callback>,
236 );
237
224You can create a time watcher by calling the C<< AnyEvent->timer >> 238You can create a time watcher by calling the C<< AnyEvent->timer >>
225method with the following mandatory arguments: 239method with the following mandatory arguments:
226 240
227C<after> specifies after how many seconds (fractional values are 241C<after> specifies after how many seconds (fractional values are
228supported) the callback should be invoked. C<cb> is the callback to invoke 242supported) the callback should be invoked. C<cb> is the callback to invoke
354Note that updating the time I<might> cause some events to be handled. 368Note that updating the time I<might> cause some events to be handled.
355 369
356=back 370=back
357 371
358=head2 SIGNAL WATCHERS 372=head2 SIGNAL WATCHERS
373
374 $w = AnyEvent->signal (signal => <uppercase_signal_name>, cb => <callback>);
359 375
360You can watch for signals using a signal watcher, C<signal> is the signal 376You can watch for signals using a signal watcher, C<signal> is the signal
361I<name> in uppercase and without any C<SIG> prefix, C<cb> is the Perl 377I<name> in uppercase and without any C<SIG> prefix, C<cb> is the Perl
362callback to be invoked whenever a signal occurs. 378callback to be invoked whenever a signal occurs.
363 379
397event loops such as L<Event> or L<Event::Lib> (and not with L<POE> 413event loops such as L<Event> or L<Event::Lib> (and not with L<POE>
398currently, as POE does it's own workaround with one-second latency). With 414currently, as POE does it's own workaround with one-second latency). With
399those, you just have to suffer the delays. 415those, you just have to suffer the delays.
400 416
401=head2 CHILD PROCESS WATCHERS 417=head2 CHILD PROCESS WATCHERS
418
419 $w = AnyEvent->child (pid => <process id>, cb => <callback>);
402 420
403You can also watch on a child process exit and catch its exit status. 421You can also watch on a child process exit and catch its exit status.
404 422
405The child process is specified by the C<pid> argument (one some backends, 423The child process is specified by the C<pid> argument (one some backends,
406using C<0> watches for any child process exit, on others this will 424using C<0> watches for any child process exit, on others this will
455 # do something else, then wait for process exit 473 # do something else, then wait for process exit
456 $done->recv; 474 $done->recv;
457 475
458=head2 IDLE WATCHERS 476=head2 IDLE WATCHERS
459 477
478 $w = AnyEvent->idle (cb => <callback>);
479
460Sometimes there is a need to do something, but it is not so important 480Sometimes there is a need to do something, but it is not so important
461to do it instantly, but only when there is nothing better to do. This 481to do it instantly, but only when there is nothing better to do. This
462"nothing better to do" is usually defined to be "no other events need 482"nothing better to do" is usually defined to be "no other events need
463attention by the event loop". 483attention by the event loop".
464 484
489 } 509 }
490 }); 510 });
491 }); 511 });
492 512
493=head2 CONDITION VARIABLES 513=head2 CONDITION VARIABLES
514
515 $cv = AnyEvent->condvar;
516
517 $cv->send (<list>);
518 my @res = $cv->recv;
494 519
495If you are familiar with some event loops you will know that all of them 520If you are familiar with some event loops you will know that all of them
496require you to run some blocking "loop", "run" or similar function that 521require you to run some blocking "loop", "run" or similar function that
497will actively watch for new events and call your callbacks. 522will actively watch for new events and call your callbacks.
498 523
1623 1648
1624# undocumented/compatibility with pre-3.4 1649# undocumented/compatibility with pre-3.4
1625*broadcast = \&send; 1650*broadcast = \&send;
1626*wait = \&_wait; 1651*wait = \&_wait;
1627 1652
1653#############################################################################
1654# "new" API, currently only emulation of it
1655#############################################################################
1656
1657package AE;
1658
1659sub io($$$) {
1660 AnyEvent->io (fh => $_[0], poll => $_[1] ? "w" : "r", cb => $_[2])
1661}
1662
1663sub timer($$$) {
1664 AnyEvent->timer (after => $_[0], interval => $_[1], cb => $_[2]);
1665}
1666
1667sub signal($$) {
1668 AnyEvent->signal (signal => $_[0], cb => $_[1]);
1669}
1670
1671sub child($$) {
1672 AnyEvent->child (pid => $_[0], cb => $_[1]);
1673}
1674
1675sub idle($) {
1676 AnyEvent->idle (cb => $_[0]);
1677}
1678
1679sub cv() {
1680 AnyEvent->condvar
1681}
1682
1683sub now() {
1684 AnyEvent->now
1685}
1686
1687sub now_update() {
1688 AnyEvent->now_update
1689}
1690
1691sub time() {
1692 AnyEvent->time
1693}
1694
1628=head1 ERROR AND EXCEPTION HANDLING 1695=head1 ERROR AND EXCEPTION HANDLING
1629 1696
1630In general, AnyEvent does not do any error handling - it relies on the 1697In general, AnyEvent does not do any error handling - it relies on the
1631caller to do that if required. The L<AnyEvent::Strict> module (see also 1698caller to do that if required. The L<AnyEvent::Strict> module (see also
1632the C<PERL_ANYEVENT_STRICT> environment variable, below) provides strict 1699the C<PERL_ANYEVENT_STRICT> environment variable, below) provides strict

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines