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

Comparing AnyEvent/README (file contents):
Revision 1.51 by root, Sun Aug 9 16:05:11 2009 UTC vs.
Revision 1.52 by root, Mon Aug 10 01:17:38 2009 UTC

643 into one. For example, a function that pings many hosts in parallel 643 into one. For example, a function that pings many hosts in parallel
644 might want to use a condition variable for the whole process. 644 might want to use a condition variable for the whole process.
645 645
646 Every call to "->begin" will increment a counter, and every call to 646 Every call to "->begin" will increment a counter, and every call to
647 "->end" will decrement it. If the counter reaches 0 in "->end", the 647 "->end" will decrement it. If the counter reaches 0 in "->end", the
648 (last) callback passed to "begin" will be executed. That callback is 648 (last) callback passed to "begin" will be executed, passing the
649 *supposed* to call "->send", but that is not required. If no 649 condvar as first argument. That callback is *supposed* to call
650 "->send", but that is not required. If no group callback was set,
650 callback was set, "send" will be called without any arguments. 651 "send" will be called without any arguments.
651 652
652 You can think of "$cv->send" giving you an OR condition (one call 653 You can think of "$cv->send" giving you an OR condition (one call
653 sends), while "$cv->begin" and "$cv->end" giving you an AND 654 sends), while "$cv->begin" and "$cv->end" giving you an AND
654 condition (all "begin" calls must be "end"'ed before the condvar 655 condition (all "begin" calls must be "end"'ed before the condvar
655 sends). 656 sends).
683 that are begung can potentially be zero: 684 that are begung can potentially be zero:
684 685
685 my $cv = AnyEvent->condvar; 686 my $cv = AnyEvent->condvar;
686 687
687 my %result; 688 my %result;
688 $cv->begin (sub { $cv->send (\%result) }); 689 $cv->begin (sub { shift->send (\%result) });
689 690
690 for my $host (@list_of_hosts) { 691 for my $host (@list_of_hosts) {
691 $cv->begin; 692 $cv->begin;
692 ping_host_then_call_callback $host, sub { 693 ping_host_then_call_callback $host, sub {
693 $result{$host} = ...; 694 $result{$host} = ...;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines