… | |
… | |
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 = '6.14'; |
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 |
… | |
… | |
2178 | For example, to force the pure perl model (L<AnyEvent::Loop::Perl>) you |
2186 | For example, to force the pure perl model (L<AnyEvent::Loop::Perl>) you |
2179 | could start your program like this: |
2187 | could start your program like this: |
2180 | |
2188 | |
2181 | PERL_ANYEVENT_MODEL=Perl perl ... |
2189 | PERL_ANYEVENT_MODEL=Perl perl ... |
2182 | |
2190 | |
|
|
2191 | =item C<PERL_ANYEVENT_IO_MODEL> |
|
|
2192 | |
|
|
2193 | The current file I/O model - see L<AnyEvent::IO> for more info. |
|
|
2194 | |
|
|
2195 | At the moment, only C<Perl> (small, pure-perl, synchronous) and |
|
|
2196 | C<IOAIO> (truly asynchronous) are supported. The default is C<IOAIO> if |
|
|
2197 | L<AnyEvent::AIO> can be loaded, otherwise it is C<Perl>. |
|
|
2198 | |
2183 | =item C<PERL_ANYEVENT_PROTOCOLS> |
2199 | =item C<PERL_ANYEVENT_PROTOCOLS> |
2184 | |
2200 | |
2185 | Used by both L<AnyEvent::DNS> and L<AnyEvent::Socket> to determine preferences |
2201 | Used by both L<AnyEvent::DNS> and L<AnyEvent::Socket> to determine preferences |
2186 | for IPv4 or IPv6. The default is unspecified (and might change, or be the result |
2202 | for IPv4 or IPv6. The default is unspecified (and might change, or be the result |
2187 | of auto probing). |
2203 | of auto probing). |
… | |
… | |
3018 | |
3034 | |
3019 | |
3035 | |
3020 | =head1 AUTHOR |
3036 | =head1 AUTHOR |
3021 | |
3037 | |
3022 | Marc Lehmann <schmorp@schmorp.de> |
3038 | Marc Lehmann <schmorp@schmorp.de> |
3023 | http://home.schmorp.de/ |
3039 | http://anyevent.schmorp.de |
3024 | |
3040 | |
3025 | =cut |
3041 | =cut |
3026 | |
3042 | |
3027 | 1 |
3043 | 1 |
3028 | |
3044 | |