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.318 by root, Wed Mar 24 23:28:06 2010 UTC vs.
Revision 1.319 by root, Thu Mar 25 21:44:59 2010 UTC

609eventually calls C<< -> send >>, and the "consumer side", which waits 609eventually calls C<< -> send >>, and the "consumer side", which waits
610for the send to occur. 610for the send to occur.
611 611
612Example: wait for a timer. 612Example: wait for a timer.
613 613
614 # wait till the result is ready 614 # condition: "wait till the timer is fired"
615 my $result_ready = AnyEvent->condvar; 615 my $timer_fired = AnyEvent->condvar;
616 616
617 # do something such as adding a timer 617 # create the timer - we could wait for, say
618 # or socket watcher the calls $result_ready->send 618 # a handle becomign ready, or even an
619 # when the "result" is ready. 619 # AnyEvent::HTTP request to finish, but
620 # in this case, we simply use a timer: 620 # in this case, we simply use a timer:
621 my $w = AnyEvent->timer ( 621 my $w = AnyEvent->timer (
622 after => 1, 622 after => 1,
623 cb => sub { $result_ready->send }, 623 cb => sub { $timer_fired->send },
624 ); 624 );
625 625
626 # this "blocks" (while handling events) till the callback 626 # this "blocks" (while handling events) till the callback
627 # calls ->send 627 # calls ->send
628 $result_ready->recv; 628 $timer_fired->recv;
629 629
630Example: wait for a timer, but take advantage of the fact that condition 630Example: wait for a timer, but take advantage of the fact that condition
631variables are also callable directly. 631variables are also callable directly.
632 632
633 my $done = AnyEvent->condvar; 633 my $done = AnyEvent->condvar;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines