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

Comparing AnyEvent/README (file contents):
Revision 1.59 by root, Tue Jan 5 10:45:25 2010 UTC vs.
Revision 1.61 by root, Wed Apr 28 14:15:55 2010 UTC

5 Qt and POE are various supported event loops/environments. 5 Qt and POE are various supported event loops/environments.
6 6
7SYNOPSIS 7SYNOPSIS
8 use AnyEvent; 8 use AnyEvent;
9 9
10 # if you prefer function calls, look at the L<AE> manpage for
11 # an alternative API.
12
10 # file descriptor readable 13 # file handle or descriptor readable
11 my $w = AnyEvent->io (fh => $fh, poll => "r", cb => sub { ... }); 14 my $w = AnyEvent->io (fh => $fh, poll => "r", cb => sub { ... });
12 15
13 # one-shot or repeating timers 16 # one-shot or repeating timers
14 my $w = AnyEvent->timer (after => $seconds, cb => sub { ... }); 17 my $w = AnyEvent->timer (after => $seconds, cb => sub { ... });
15 my $w = AnyEvent->timer (after => $seconds, interval => $seconds, cb => ... 18 my $w = AnyEvent->timer (after => $seconds, interval => $seconds, cb => ...
468 problems mentioned in the description of signal watchers apply. 471 problems mentioned in the description of signal watchers apply.
469 472
470 Example: fork a process and wait for it 473 Example: fork a process and wait for it
471 474
472 my $done = AnyEvent->condvar; 475 my $done = AnyEvent->condvar;
473 476
474 my $pid = fork or exit 5; 477 my $pid = fork or exit 5;
475 478
476 my $w = AnyEvent->child ( 479 my $w = AnyEvent->child (
477 pid => $pid, 480 pid => $pid,
478 cb => sub { 481 cb => sub {
479 my ($pid, $status) = @_; 482 my ($pid, $status) = @_;
480 warn "pid $pid exited with status $status"; 483 warn "pid $pid exited with status $status";
481 $done->send; 484 $done->send;
482 }, 485 },
483 ); 486 );
484 487
485 # do something else, then wait for process exit 488 # do something else, then wait for process exit
486 $done->recv; 489 $done->recv;
487 490
488 IDLE WATCHERS 491 IDLE WATCHERS
489 $w = AnyEvent->idle (cb => <callback>); 492 $w = AnyEvent->idle (cb => <callback>);
490 493
589 which eventually calls "-> send", and the "consumer side", which waits 592 which eventually calls "-> send", and the "consumer side", which waits
590 for the send to occur. 593 for the send to occur.
591 594
592 Example: wait for a timer. 595 Example: wait for a timer.
593 596
594 # wait till the result is ready 597 # condition: "wait till the timer is fired"
595 my $result_ready = AnyEvent->condvar; 598 my $timer_fired = AnyEvent->condvar;
596 599
597 # do something such as adding a timer 600 # create the timer - we could wait for, say
598 # or socket watcher the calls $result_ready->send 601 # a handle becomign ready, or even an
599 # when the "result" is ready. 602 # AnyEvent::HTTP request to finish, but
600 # in this case, we simply use a timer: 603 # in this case, we simply use a timer:
601 my $w = AnyEvent->timer ( 604 my $w = AnyEvent->timer (
602 after => 1, 605 after => 1,
603 cb => sub { $result_ready->send }, 606 cb => sub { $timer_fired->send },
604 ); 607 );
605 608
606 # this "blocks" (while handling events) till the callback 609 # this "blocks" (while handling events) till the callback
607 # calls ->send 610 # calls ->send
608 $result_ready->recv; 611 $timer_fired->recv;
609 612
610 Example: wait for a timer, but take advantage of the fact that condition 613 Example: wait for a timer, but take advantage of the fact that condition
611 variables are also callable directly. 614 variables are also callable directly.
612 615
613 my $done = AnyEvent->condvar; 616 my $done = AnyEvent->condvar;
1076 Has special support for AnyEvent via Coro::AnyEvent. 1079 Has special support for AnyEvent via Coro::AnyEvent.
1077 1080
1078SIMPLIFIED AE API 1081SIMPLIFIED AE API
1079 Starting with version 5.0, AnyEvent officially supports a second, much 1082 Starting with version 5.0, AnyEvent officially supports a second, much
1080 simpler, API that is designed to reduce the calling, typing and memory 1083 simpler, API that is designed to reduce the calling, typing and memory
1081 overhead. 1084 overhead by using function call syntax and a fixed number of parameters.
1082 1085
1083 See the AE manpage for details. 1086 See the AE manpage for details.
1084 1087
1085ERROR AND EXCEPTION HANDLING 1088ERROR AND EXCEPTION HANDLING
1086 In general, AnyEvent does not do any error handling - it relies on the 1089 In general, AnyEvent does not do any error handling - it relies on the
1351 1354
1352 The actual code goes further and collects all errors ("die"s, 1355 The actual code goes further and collects all errors ("die"s,
1353 exceptions) that occurred during request processing. The "result" method 1356 exceptions) that occurred during request processing. The "result" method
1354 detects whether an exception as thrown (it is stored inside the $txn 1357 detects whether an exception as thrown (it is stored inside the $txn
1355 object) and just throws the exception, which means connection errors and 1358 object) and just throws the exception, which means connection errors and
1356 other problems get reported tot he code that tries to use the result, 1359 other problems get reported to the code that tries to use the result,
1357 not in a random callback. 1360 not in a random callback.
1358 1361
1359 All of this enables the following usage styles: 1362 All of this enables the following usage styles:
1360 1363
1361 1. Blocking: 1364 1. Blocking:
1774 clock is available, can take avdantage of advanced kernel interfaces 1777 clock is available, can take avdantage of advanced kernel interfaces
1775 such as "epoll" and "kqueue", and is the fastest backend *by far*. 1778 such as "epoll" and "kqueue", and is the fastest backend *by far*.
1776 You can even embed Glib/Gtk2 in it (or vice versa, see EV::Glib and 1779 You can even embed Glib/Gtk2 in it (or vice versa, see EV::Glib and
1777 Glib::EV). 1780 Glib::EV).
1778 1781
1782 If you only use backends that rely on another event loop (e.g.
1783 "Tk"), then this module will do nothing for you.
1784
1779 Guard 1785 Guard
1780 The guard module, when used, will be used to implement 1786 The guard module, when used, will be used to implement
1781 "AnyEvent::Util::guard". This speeds up guards considerably (and 1787 "AnyEvent::Util::guard". This speeds up guards considerably (and
1782 uses a lot less memory), but otherwise doesn't affect guard 1788 uses a lot less memory), but otherwise doesn't affect guard
1783 operation much. It is purely used for performance. 1789 operation much. It is purely used for performance.
1784 1790
1785 JSON and JSON::XS 1791 JSON and JSON::XS
1786 One of these modules is required when you want to read or write JSON 1792 One of these modules is required when you want to read or write JSON
1787 data via AnyEvent::Handle. It is also written in pure-perl, but can 1793 data via AnyEvent::Handle. JSON is also written in pure-perl, but
1788 take advantage of the ultra-high-speed JSON::XS module when it is 1794 can take advantage of the ultra-high-speed JSON::XS module when it
1789 installed. 1795 is installed.
1790
1791 In fact, AnyEvent::Handle will use JSON::XS by default if it is
1792 installed.
1793 1796
1794 Net::SSLeay 1797 Net::SSLeay
1795 Implementing TLS/SSL in Perl is certainly interesting, but not very 1798 Implementing TLS/SSL in Perl is certainly interesting, but not very
1796 worthwhile: If this module is installed, then AnyEvent::Handle (with 1799 worthwhile: If this module is installed, then AnyEvent::Handle (with
1797 the help of AnyEvent::TLS), gains the ability to do TLS/SSL. 1800 the help of AnyEvent::TLS), gains the ability to do TLS/SSL.
1840 1843
1841 You can make AnyEvent completely ignore this variable by deleting it 1844 You can make AnyEvent completely ignore this variable by deleting it
1842 before the first watcher gets created, e.g. with a "BEGIN" block: 1845 before the first watcher gets created, e.g. with a "BEGIN" block:
1843 1846
1844 BEGIN { delete $ENV{PERL_ANYEVENT_MODEL} } 1847 BEGIN { delete $ENV{PERL_ANYEVENT_MODEL} }
1845 1848
1846 use AnyEvent; 1849 use AnyEvent;
1847 1850
1848 Similar considerations apply to $ENV{PERL_ANYEVENT_VERBOSE}, as that can 1851 Similar considerations apply to $ENV{PERL_ANYEVENT_VERBOSE}, as that can
1849 be used to probe what backend is used and gain other information (which 1852 be used to probe what backend is used and gain other information (which
1850 is probably even less useful to an attacker than PERL_ANYEVENT_MODEL), 1853 is probably even less useful to an attacker than PERL_ANYEVENT_MODEL),
1851 and $ENV{PERL_ANYEVENT_STRICT}. 1854 and $ENV{PERL_ANYEVENT_STRICT}.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines