1 | =head1 NAME |
1 | =head1 NAME |
2 | |
2 | |
3 | AnyEvent - provide framework for multiple event loops |
3 | AnyEvent - events independent of event loop implementation |
4 | |
4 | |
5 | EV, Event, Glib, Tk, Perl, Event::Lib, Qt and POE are various supported |
5 | EV, Event, Glib, Tk, Perl, Event::Lib, Qt and POE are various supported |
6 | event loops. |
6 | event loops. |
7 | |
7 | |
8 | =head1 SYNOPSIS |
8 | =head1 SYNOPSIS |
… | |
… | |
40 | =head1 INTRODUCTION/TUTORIAL |
40 | =head1 INTRODUCTION/TUTORIAL |
41 | |
41 | |
42 | This manpage is mainly a reference manual. If you are interested |
42 | This manpage is mainly a reference manual. If you are interested |
43 | in a tutorial or some gentle introduction, have a look at the |
43 | in a tutorial or some gentle introduction, have a look at the |
44 | L<AnyEvent::Intro> manpage. |
44 | L<AnyEvent::Intro> manpage. |
|
|
45 | |
|
|
46 | =head1 SUPPORT |
|
|
47 | |
|
|
48 | There is a mailinglist for discussing all things AnyEvent, and an IRC |
|
|
49 | channel, too. |
|
|
50 | |
|
|
51 | See the AnyEvent project page at the B<Schmorpforge Ta-Sa Software |
|
|
52 | Respository>, at L<http://anyevent.schmorp.de>, for more info. |
45 | |
53 | |
46 | =head1 WHY YOU SHOULD USE THIS MODULE (OR NOT) |
54 | =head1 WHY YOU SHOULD USE THIS MODULE (OR NOT) |
47 | |
55 | |
48 | Glib, POE, IO::Async, Event... CPAN offers event models by the dozen |
56 | Glib, POE, IO::Async, Event... CPAN offers event models by the dozen |
49 | nowadays. So what is different about AnyEvent? |
57 | nowadays. So what is different about AnyEvent? |
… | |
… | |
509 | Condition variables are similar to callbacks, except that you can |
517 | Condition variables are similar to callbacks, except that you can |
510 | optionally wait for them. They can also be called merge points - points |
518 | optionally wait for them. They can also be called merge points - points |
511 | in time where multiple outstanding events have been processed. And yet |
519 | in time where multiple outstanding events have been processed. And yet |
512 | another way to call them is transactions - each condition variable can be |
520 | another way to call them is transactions - each condition variable can be |
513 | used to represent a transaction, which finishes at some point and delivers |
521 | used to represent a transaction, which finishes at some point and delivers |
514 | a result. |
522 | a result. And yet some people know them as "futures" - a promise to |
|
|
523 | compute/deliver something that you can wait for. |
515 | |
524 | |
516 | Condition variables are very useful to signal that something has finished, |
525 | Condition variables are very useful to signal that something has finished, |
517 | for example, if you write a module that does asynchronous http requests, |
526 | for example, if you write a module that does asynchronous http requests, |
518 | then a condition variable would be the ideal candidate to signal the |
527 | then a condition variable would be the ideal candidate to signal the |
519 | availability of results. The user can either act when the callback is |
528 | availability of results. The user can either act when the callback is |
… | |
… | |
870 | event module detection too early, for example, L<AnyEvent::AIO> creates |
879 | event module detection too early, for example, L<AnyEvent::AIO> creates |
871 | and installs the global L<IO::AIO> watcher in a C<post_detect> block to |
880 | and installs the global L<IO::AIO> watcher in a C<post_detect> block to |
872 | avoid autodetecting the event module at load time. |
881 | avoid autodetecting the event module at load time. |
873 | |
882 | |
874 | If called in scalar or list context, then it creates and returns an object |
883 | If called in scalar or list context, then it creates and returns an object |
875 | that automatically removes the callback again when it is destroyed. See |
884 | that automatically removes the callback again when it is destroyed (or |
|
|
885 | C<undef> when the hook was immediately executed). See L<AnyEvent::AIO> for |
876 | L<Coro::BDB> for a case where this is useful. |
886 | a case where this is useful. |
|
|
887 | |
|
|
888 | Example: Create a watcher for the IO::AIO module and store it in |
|
|
889 | C<$WATCHER>. Only do so after the event loop is initialised, though. |
|
|
890 | |
|
|
891 | our WATCHER; |
|
|
892 | |
|
|
893 | my $guard = AnyEvent::post_detect { |
|
|
894 | $WATCHER = AnyEvent->io (fh => IO::AIO::poll_fileno, poll => 'r', cb => \&IO::AIO::poll_cb); |
|
|
895 | }; |
|
|
896 | |
|
|
897 | # the ||= is important in case post_detect immediately runs the block, |
|
|
898 | # as to not clobber the newly-created watcher. assigning both watcher and |
|
|
899 | # post_detect guard to the same variable has the advantage of users being |
|
|
900 | # able to just C<undef $WATCHER> if the watcher causes them grief. |
|
|
901 | |
|
|
902 | $WATCHER ||= $guard; |
877 | |
903 | |
878 | =item @AnyEvent::post_detect |
904 | =item @AnyEvent::post_detect |
879 | |
905 | |
880 | If there are any code references in this array (you can C<push> to it |
906 | If there are any code references in this array (you can C<push> to it |
881 | before or after loading AnyEvent), then they will called directly after |
907 | before or after loading AnyEvent), then they will called directly after |
… | |
… | |
1058 | |
1084 | |
1059 | BEGIN { AnyEvent::common_sense } |
1085 | BEGIN { AnyEvent::common_sense } |
1060 | |
1086 | |
1061 | use Carp (); |
1087 | use Carp (); |
1062 | |
1088 | |
1063 | our $VERSION = 4.85; |
1089 | our $VERSION = 4.86; |
1064 | our $MODEL; |
1090 | our $MODEL; |
1065 | |
1091 | |
1066 | our $AUTOLOAD; |
1092 | our $AUTOLOAD; |
1067 | our @ISA; |
1093 | our @ISA; |
1068 | |
1094 | |
… | |
… | |
1126 | my ($cb) = @_; |
1152 | my ($cb) = @_; |
1127 | |
1153 | |
1128 | if ($MODEL) { |
1154 | if ($MODEL) { |
1129 | $cb->(); |
1155 | $cb->(); |
1130 | |
1156 | |
1131 | 1 |
1157 | undef |
1132 | } else { |
1158 | } else { |
1133 | push @post_detect, $cb; |
1159 | push @post_detect, $cb; |
1134 | |
1160 | |
1135 | defined wantarray |
1161 | defined wantarray |
1136 | ? bless \$cb, "AnyEvent::Util::postdetect" |
1162 | ? bless \$cb, "AnyEvent::Util::postdetect" |
… | |
… | |
2313 | |
2339 | |
2314 | =item L<JSON> and L<JSON::XS> |
2340 | =item L<JSON> and L<JSON::XS> |
2315 | |
2341 | |
2316 | This module is required when you want to read or write JSON data via |
2342 | This module is required when you want to read or write JSON data via |
2317 | L<AnyEvent::Handle>. It is also written in pure-perl, but can take |
2343 | L<AnyEvent::Handle>. It is also written in pure-perl, but can take |
2318 | advantage of the ulta-high-speed L<JSON::XS> module when it is installed. |
2344 | advantage of the ultra-high-speed L<JSON::XS> module when it is installed. |
2319 | |
2345 | |
2320 | In fact, L<AnyEvent::Handle> will use L<JSON::XS> by default if it is |
2346 | In fact, L<AnyEvent::Handle> will use L<JSON::XS> by default if it is |
2321 | installed. |
2347 | installed. |
2322 | |
2348 | |
2323 | =item L<Net::SSLeay> |
2349 | =item L<Net::SSLeay> |