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.405 by root, Tue Aug 14 02:28:22 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 = '7.02'; 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
2921This 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
2922chosen 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
2923pure-perl event loop (L<AnyEvent::Loop>) will additionally load it to 2931pure-perl event loop (L<AnyEvent::Loop>) will additionally load it to
2924try to use a monotonic clock for timing stability. 2932try to use a monotonic clock for timing stability.
2925 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
2926=back 2944=back
2927 2945
2928 2946
2929=head1 FORK 2947=head1 FORK
2930 2948

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines