--- AnyEvent/lib/AnyEvent.pm 2008/07/09 10:36:22 1.169 +++ AnyEvent/lib/AnyEvent.pm 2008/08/20 12:37:21 1.176 @@ -8,17 +8,26 @@ use AnyEvent; - my $w = AnyEvent->io (fh => $fh, poll => "r|w", cb => sub { - ... - }); + my $w = AnyEvent->io (fh => $fh, poll => "r|w", cb => sub { ... }); + + my $w = AnyEvent->timer (after => $seconds, cb => sub { ... }); + my $w = AnyEvent->timer (after => $seconds, interval => $seconds, cb => ... + + print AnyEvent->now; # prints current event loop time + print AnyEvent->time; # think Time::HiRes::time or simply CORE::time. - my $w = AnyEvent->timer (after => $seconds, cb => sub { + my $w = AnyEvent->signal (signal => "TERM", cb => sub { ... }); + + my $w = AnyEvent->child (pid => $pid, cb => sub { + my ($pid, $status) = @_; ... }); my $w = AnyEvent->condvar; # stores whether a condition was flagged $w->send; # wake up current and all future recv's $w->recv; # enters "main loop" till $condvar gets ->send + # use a condvar in callback mode: + $w->cb (sub { $_[0]->recv }); =head1 INTRODUCTION/TUTORIAL @@ -383,8 +392,10 @@ Condition variables can be created by calling the C<< AnyEvent->condvar >> method, usually without arguments. The only argument pair allowed is + C, which specifies a callback to be called when the condition variable -becomes true. +becomes true, with the condition variable as the first argument (but not +the results). After creation, the condition variable is "false" until it becomes "true" by calling the C method (or calling the condition variable as if it @@ -450,6 +461,23 @@ my $delay = AnyEvent->timer (after => 5, cb => $done); $done->recv; +Example: Imagine an API that returns a condvar and doesn't support +callbacks. This is how you make a synchronous call, for example from +the main program: + + use AnyEvent::CouchDB; + + ... + + my @info = $couchdb->info->recv; + +And this is how you would just ste a callback to be called whenever the +results are available: + + $couchdb->info->cb (sub { + my @info = $_[0]->recv; + }); + =head3 METHODS FOR PRODUCERS These methods should only be used by the producing side, i.e. the @@ -592,7 +620,7 @@ Returns true when the condition is "true", i.e. whether C or C have been called. -=item $cb = $cv->cb ([new callback]) +=item $cb = $cv->cb ($cb->($cv)) This is a mutator function that returns the callback set and optionally replaces it before doing so. @@ -828,7 +856,7 @@ use Carp; -our $VERSION = 4.2; +our $VERSION = 4.231; our $MODEL; our $AUTOLOAD; @@ -1208,10 +1236,14 @@ AnyEvent does not do much argument checking by default, as thorough argument checking is very costly. Setting this variable to a true value -will cause AnyEvent to thoroughly check the arguments passed to most -method calls and croaks if it finds any problems. In other words, enables -"strict" mode. Unlike C it is definitely recommended ot keep -it off in production. +will cause AnyEvent to load C and then to thoroughly +check the arguments passed to most method calls. If it finds any problems +it will croak. + +In other words, enables "strict" mode. + +Unlike C it is definitely recommended ot keep it off in +production. =item C