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

Comparing AnyEvent/lib/AnyEvent.pm (file contents):
Revision 1.399 by root, Tue Mar 27 23:47:57 2012 UTC vs.
Revision 1.409 by root, Thu Dec 6 12:10:09 2012 UTC

763 }; 763 };
764 } 764 }
765 765
766 $cv->end; 766 $cv->end;
767 767
768 ...
769
770 my $results = $cv->recv;
771
768This code fragment supposedly pings a number of hosts and calls 772This code fragment supposedly pings a number of hosts and calls
769C<send> after results for all then have have been gathered - in any 773C<send> after results for all then have have been gathered - in any
770order. To achieve this, the code issues a call to C<begin> when it starts 774order. To achieve this, the code issues a call to C<begin> when it starts
771each ping request and calls C<end> when it has received some result for 775each ping request and calls C<end> when it has received some result for
772it. Since C<begin> and C<end> only maintain a counter, the order in which 776it. Since C<begin> and C<end> only maintain a counter, the order in which
807 811
808In list context, all parameters passed to C<send> will be returned, 812In list context, all parameters passed to C<send> will be returned,
809in scalar context only the first one will be returned. 813in scalar context only the first one will be returned.
810 814
811Note that doing a blocking wait in a callback is not supported by any 815Note that doing a blocking wait in a callback is not supported by any
812event loop, that is, recursive invocation of a blocking C<< ->recv 816event 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 817not allowed and the C<recv> call will C<croak> if such a condition is
814condition is detected. This condition can be slightly loosened by using 818detected. This requirement can be dropped by relying on L<Coro::AnyEvent>
815L<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
816any thread that doesn't run the event loop itself. 820that doesn't run the event loop itself. L<Coro::AnyEvent> is loaded
821automatically when L<Coro> is used with L<AnyEvent>, so code does not need
822to do anything special to take advantage of that: any code that would
823normally block your program because it calls C<recv>, be executed in an
824C<async> thread instead without blocking other threads.
817 825
818Not all event models support a blocking wait - some die in that case 826Not 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
820using this from a module, never require a blocking wait>. Instead, let the 828using this from a module, never require a blocking wait>. Instead, let the
821caller decide whether the call will block or not (for example, by coupling 829caller decide whether the call will block or not (for example, by coupling
1234 1242
1235BEGIN { AnyEvent::common_sense } 1243BEGIN { AnyEvent::common_sense }
1236 1244
1237use Carp (); 1245use Carp ();
1238 1246
1239our $VERSION = '6.14'; 1247our $VERSION = '7.04';
1240our $MODEL; 1248our $MODEL;
1241our @ISA; 1249our @ISA;
1242our @REGISTRY; 1250our @REGISTRY;
1243our $VERBOSE; 1251our $VERBOSE;
1244our %PROTOCOL; # (ipv4|ipv6) => (1|2), higher numbers are preferred 1252our %PROTOCOL; # (ipv4|ipv6) => (1|2), higher numbers are preferred
2178For example, to force the pure perl model (L<AnyEvent::Loop::Perl>) you 2186For example, to force the pure perl model (L<AnyEvent::Loop::Perl>) you
2179could start your program like this: 2187could 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
2193The current file I/O model - see L<AnyEvent::IO> for more info.
2194
2195At the moment, only C<Perl> (small, pure-perl, synchronous) and
2196C<IOAIO> (truly asynchronous) are supported. The default is C<IOAIO> if
2197L<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
2185Used by both L<AnyEvent::DNS> and L<AnyEvent::Socket> to determine preferences 2201Used by both L<AnyEvent::DNS> and L<AnyEvent::Socket> to determine preferences
2186for IPv4 or IPv6. The default is unspecified (and might change, or be the result 2202for IPv4 or IPv6. The default is unspecified (and might change, or be the result
2187of auto probing). 2203of 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
30271 30431
3028 3044

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines