… | |
… | |
763 | }; |
763 | }; |
764 | } |
764 | } |
765 | |
765 | |
766 | $cv->end; |
766 | $cv->end; |
767 | |
767 | |
|
|
768 | ... |
|
|
769 | |
|
|
770 | my $results = $cv->recv; |
|
|
771 | |
768 | This code fragment supposedly pings a number of hosts and calls |
772 | This code fragment supposedly pings a number of hosts and calls |
769 | C<send> after results for all then have have been gathered - in any |
773 | C<send> after results for all then have have been gathered - in any |
770 | order. To achieve this, the code issues a call to C<begin> when it starts |
774 | order. To achieve this, the code issues a call to C<begin> when it starts |
771 | each ping request and calls C<end> when it has received some result for |
775 | each ping request and calls C<end> when it has received some result for |
772 | it. Since C<begin> and C<end> only maintain a counter, the order in which |
776 | it. Since C<begin> and C<end> only maintain a counter, the order in which |
… | |
… | |
807 | |
811 | |
808 | In list context, all parameters passed to C<send> will be returned, |
812 | In list context, all parameters passed to C<send> will be returned, |
809 | in scalar context only the first one will be returned. |
813 | in scalar context only the first one will be returned. |
810 | |
814 | |
811 | Note that doing a blocking wait in a callback is not supported by any |
815 | Note that doing a blocking wait in a callback is not supported by any |
812 | event loop, that is, recursive invocation of a blocking C<< ->recv |
816 | event loop, that is, recursive invocation of a blocking C<< ->recv >> is |
813 | >> is not allowed, and the C<recv> call will C<croak> if such a |
817 | not allowed and the C<recv> call will C<croak> if such a condition is |
814 | condition is detected. This condition can be slightly loosened by using |
818 | detected. This requirement can be dropped by relying on L<Coro::AnyEvent> |
815 | L<Coro::AnyEvent>, which allows you to do a blocking C<< ->recv >> from |
819 | , which allows you to do a blocking C<< ->recv >> from any thread |
816 | any thread that doesn't run the event loop itself. |
820 | that doesn't run the event loop itself. L<Coro::AnyEvent> is loaded |
|
|
821 | automatically when L<Coro> is used with L<AnyEvent>, so code does not need |
|
|
822 | to do anything special to take advantage of that: any code that would |
|
|
823 | normally block your program because it calls C<recv>, be executed in an |
|
|
824 | C<async> thread instead without blocking other threads. |
817 | |
825 | |
818 | Not all event models support a blocking wait - some die in that case |
826 | Not all event models support a blocking wait - some die in that case |
819 | (programs might want to do that to stay interactive), so I<if you are |
827 | (programs might want to do that to stay interactive), so I<if you are |
820 | using this from a module, never require a blocking wait>. Instead, let the |
828 | using this from a module, never require a blocking wait>. Instead, let the |
821 | caller decide whether the call will block or not (for example, by coupling |
829 | caller decide whether the call will block or not (for example, by coupling |
… | |
… | |
1234 | |
1242 | |
1235 | BEGIN { AnyEvent::common_sense } |
1243 | BEGIN { AnyEvent::common_sense } |
1236 | |
1244 | |
1237 | use Carp (); |
1245 | use Carp (); |
1238 | |
1246 | |
1239 | our $VERSION = '7.03'; |
1247 | our $VERSION = '7.04'; |
1240 | our $MODEL; |
1248 | our $MODEL; |
1241 | our @ISA; |
1249 | our @ISA; |
1242 | our @REGISTRY; |
1250 | our @REGISTRY; |
1243 | our $VERBOSE; |
1251 | our $VERBOSE; |
1244 | our %PROTOCOL; # (ipv4|ipv6) => (1|2), higher numbers are preferred |
1252 | our %PROTOCOL; # (ipv4|ipv6) => (1|2), higher numbers are preferred |
… | |
… | |
2921 | This module is part of perl since release 5.008. It will be used when the |
2929 | This module is part of perl since release 5.008. It will be used when the |
2922 | chosen event library does not come with a timing source of its own. The |
2930 | chosen event library does not come with a timing source of its own. The |
2923 | pure-perl event loop (L<AnyEvent::Loop>) will additionally load it to |
2931 | pure-perl event loop (L<AnyEvent::Loop>) will additionally load it to |
2924 | try to use a monotonic clock for timing stability. |
2932 | try to use a monotonic clock for timing stability. |
2925 | |
2933 | |
|
|
2934 | =item L<AnyEvent::AIO> (and L<IO::AIO>) |
|
|
2935 | |
|
|
2936 | The default implementation of L<AnyEvent::IO> is to do I/O synchronously, |
|
|
2937 | stopping programs while they access the disk, which is fine for a lot of |
|
|
2938 | programs. |
|
|
2939 | |
|
|
2940 | Installing AnyEvent::AIO (and its IO::AIO dependency) makes it switch to |
|
|
2941 | a true asynchronous implementation, so event processing can continue even |
|
|
2942 | while waiting for disk I/O. |
|
|
2943 | |
2926 | =back |
2944 | =back |
2927 | |
2945 | |
2928 | |
2946 | |
2929 | =head1 FORK |
2947 | =head1 FORK |
2930 | |
2948 | |