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.279 by root, Sun Aug 9 16:05:11 2009 UTC vs.
Revision 1.286 by root, Fri Aug 21 11:59:25 2009 UTC

592 after => 1, 592 after => 1,
593 cb => sub { $result_ready->send }, 593 cb => sub { $result_ready->send },
594 ); 594 );
595 595
596 # this "blocks" (while handling events) till the callback 596 # this "blocks" (while handling events) till the callback
597 # calls -<send 597 # calls ->send
598 $result_ready->recv; 598 $result_ready->recv;
599 599
600Example: wait for a timer, but take advantage of the fact that condition 600Example: wait for a timer, but take advantage of the fact that condition
601variables are also callable directly. 601variables are also callable directly.
602 602
666one. For example, a function that pings many hosts in parallel might want 666one. For example, a function that pings many hosts in parallel might want
667to use a condition variable for the whole process. 667to use a condition variable for the whole process.
668 668
669Every call to C<< ->begin >> will increment a counter, and every call to 669Every call to C<< ->begin >> will increment a counter, and every call to
670C<< ->end >> will decrement it. If the counter reaches C<0> in C<< ->end 670C<< ->end >> will decrement it. If the counter reaches C<0> in C<< ->end
671>>, the (last) callback passed to C<begin> will be executed. That callback 671>>, the (last) callback passed to C<begin> will be executed, passing the
672is I<supposed> to call C<< ->send >>, but that is not required. If no 672condvar as first argument. That callback is I<supposed> to call C<< ->send
673callback was set, C<send> will be called without any arguments. 673>>, but that is not required. If no group callback was set, C<send> will
674be called without any arguments.
674 675
675You can think of C<< $cv->send >> giving you an OR condition (one call 676You can think of C<< $cv->send >> giving you an OR condition (one call
676sends), while C<< $cv->begin >> and C<< $cv->end >> giving you an AND 677sends), while C<< $cv->begin >> and C<< $cv->end >> giving you an AND
677condition (all C<begin> calls must be C<end>'ed before the condvar sends). 678condition (all C<begin> calls must be C<end>'ed before the condvar sends).
678 679
705begung can potentially be zero: 706begung can potentially be zero:
706 707
707 my $cv = AnyEvent->condvar; 708 my $cv = AnyEvent->condvar;
708 709
709 my %result; 710 my %result;
710 $cv->begin (sub { $cv->send (\%result) }); 711 $cv->begin (sub { shift->send (\%result) });
711 712
712 for my $host (@list_of_hosts) { 713 for my $host (@list_of_hosts) {
713 $cv->begin; 714 $cv->begin;
714 ping_host_then_call_callback $host, sub { 715 ping_host_then_call_callback $host, sub {
715 $result{$host} = ...; 716 $result{$host} = ...;
1115 1116
1116BEGIN { AnyEvent::common_sense } 1117BEGIN { AnyEvent::common_sense }
1117 1118
1118use Carp (); 1119use Carp ();
1119 1120
1120our $VERSION = '5.0'; 1121our $VERSION = '5.112';
1121our $MODEL; 1122our $MODEL;
1122 1123
1123our $AUTOLOAD; 1124our $AUTOLOAD;
1124our @ISA; 1125our @ISA;
1125 1126

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines