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.51 by root, Wed Apr 16 15:10:10 2008 UTC vs.
Revision 1.52 by root, Sat Apr 19 03:47:24 2008 UTC

14 14
15 my $w = AnyEvent->timer (after => $seconds, cb => sub { 15 my $w = AnyEvent->timer (after => $seconds, cb => sub {
16 ... 16 ...
17 }); 17 });
18 18
19 my $w = AnyEvent->condvar; # stores wether a condition was flagged 19 my $w = AnyEvent->condvar; # stores whether a condition was flagged
20 $w->wait; # enters "main loop" till $condvar gets ->broadcast 20 $w->wait; # enters "main loop" till $condvar gets ->broadcast
21 $w->broadcast; # wake up current and all future wait's 21 $w->broadcast; # wake up current and all future wait's
22 22
23=head1 WHY YOU SHOULD USE THIS MODULE (OR NOT) 23=head1 WHY YOU SHOULD USE THIS MODULE (OR NOT)
24 24
74 74
75The interface itself is vaguely similar but not identical to the Event 75The interface itself is vaguely similar but not identical to the Event
76module. 76module.
77 77
78On the first call of any method, the module tries to detect the currently 78On the first call of any method, the module tries to detect the currently
79loaded event loop by probing wether any of the following modules is 79loaded event loop by probing whether any of the following modules is
80loaded: L<Coro::EV>, L<Coro::Event>, L<EV>, L<Event>, L<Glib>, L<Tk>. The 80loaded: L<Coro::EV>, L<Coro::Event>, L<EV>, L<Event>, L<Glib>, L<Tk>. The
81first one found is used. If none are found, the module tries to load these 81first one found is used. If none are found, the module tries to load these
82modules in the order given. The first one that could be successfully 82modules in the order given. The first one that could be successfully
83loaded will be used. If still none could be found, AnyEvent will fall back 83loaded will be used. If still none could be found, AnyEvent will fall back
84to a pure-perl event loop, which is also not very efficient. 84to a pure-perl event loop, which is also not very efficient.
181immediately. 181immediately.
182 182
183Not all event models support a blocking wait - some die in that case 183Not all event models support a blocking wait - some die in that case
184(programs might want to do that so they stay interactive), so I<if you 184(programs might want to do that so they stay interactive), so I<if you
185are using this from a module, never require a blocking wait>, but let the 185are using this from a module, never require a blocking wait>, but let the
186caller decide wether the call will block or not (for example, by coupling 186caller decide whether the call will block or not (for example, by coupling
187condition variables with some kind of request results and supporting 187condition variables with some kind of request results and supporting
188callbacks so the caller knows that getting the result will not block, 188callbacks so the caller knows that getting the result will not block,
189while still suppporting blocking waits if the caller so desires). 189while still suppporting blocking waits if the caller so desires).
190 190
191Another reason I<never> to C<< ->wait >> in a module is that you cannot 191Another reason I<never> to C<< ->wait >> in a module is that you cannot
627 $txn->{finished}->wait; 627 $txn->{finished}->wait;
628 return $txn->{result}; 628 return $txn->{result};
629 629
630The actual code goes further and collects all errors (C<die>s, exceptions) 630The actual code goes further and collects all errors (C<die>s, exceptions)
631that occured during request processing. The C<result> method detects 631that occured during request processing. The C<result> method detects
632wether an exception as thrown (it is stored inside the $txn object) 632whether an exception as thrown (it is stored inside the $txn object)
633and just throws the exception, which means connection errors and other 633and just throws the exception, which means connection errors and other
634problems get reported tot he code that tries to use the result, not in a 634problems get reported tot he code that tries to use the result, not in a
635random callback. 635random callback.
636 636
637All of this enables the following usage styles: 637All of this enables the following usage styles:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines