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.410 by root, Fri Mar 1 06:03:21 2013 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).
2913This module is part of perl since release 5.008. It will be used when the 2929This module is part of perl since release 5.008. It will be used when the
2914chosen event library does not come with a timing source of its own. The 2930chosen event library does not come with a timing source of its own. The
2915pure-perl event loop (L<AnyEvent::Loop>) will additionally load it to 2931pure-perl event loop (L<AnyEvent::Loop>) will additionally load it to
2916try to use a monotonic clock for timing stability. 2932try to use a monotonic clock for timing stability.
2917 2933
2934=item L<AnyEvent::AIO> (and L<IO::AIO>)
2935
2936The default implementation of L<AnyEvent::IO> is to do I/O synchronously,
2937stopping programs while they access the disk, which is fine for a lot of
2938programs.
2939
2940Installing AnyEvent::AIO (and its IO::AIO dependency) makes it switch to
2941a true asynchronous implementation, so event processing can continue even
2942while waiting for disk I/O.
2943
2918=back 2944=back
2919 2945
2920 2946
2921=head1 FORK 2947=head1 FORK
2922 2948
3018 3044
3019 3045
3020=head1 AUTHOR 3046=head1 AUTHOR
3021 3047
3022 Marc Lehmann <schmorp@schmorp.de> 3048 Marc Lehmann <schmorp@schmorp.de>
3023 http://home.schmorp.de/ 3049 http://anyevent.schmorp.de
3024 3050
3025=cut 3051=cut
3026 3052
30271 30531
3028 3054

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines