--- AnyEvent/lib/AnyEvent.pm 2008/05/24 17:21:50 1.130 +++ AnyEvent/lib/AnyEvent.pm 2008/05/24 17:48:38 1.131 @@ -313,7 +313,8 @@ becomes true. After creation, the condition variable is "false" until it becomes "true" -by calling the C method. +by calling the C method (or calling the condition variable as if it +were a callback). Condition variables are similar to callbacks, except that you can optionally wait for them. They can also be called merge points - points @@ -349,7 +350,7 @@ eventually calls C<< -> send >>, and the "consumer side", which waits for the send to occur. -Example: +Example: wait for a timer. # wait till the result is ready my $result_ready = AnyEvent->condvar; @@ -367,6 +368,13 @@ # calls send $result_ready->recv; +Example: wait for a timer, but take advantage of the fact that +condition variables are also code references. + + my $done = AnyEvent->condvar; + my $delay = AnyEvent->timer (after => 5, cb => $done); + $done->recv; + =head3 METHODS FOR PRODUCERS These methods should only be used by the producing side, i.e. the @@ -388,6 +396,9 @@ Any arguments passed to the C call will be returned by all future C<< ->recv >> calls. +Condition variables are overloaded so one can call them directly (as a +code reference). Calling them directly is the same as calling C. + =item $cv->croak ($error) Similar to send, but causes all call's to C<< ->recv >> to invoke @@ -916,6 +927,10 @@ package AnyEvent::CondVar::Base; +use overload + '&{}' => sub { my $self = shift; sub { $self->send (@_) } }, + fallback => 1; + sub _send { # nop }