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.60 by root, Mon Apr 12 02:50:31 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 => ...
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.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines