… | |
… | |
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 | |
75 | The interface itself is vaguely similar but not identical to the Event |
75 | The interface itself is vaguely similar but not identical to the Event |
76 | module. |
76 | module. |
77 | |
77 | |
78 | On the first call of any method, the module tries to detect the currently |
78 | On the first call of any method, the module tries to detect the currently |
79 | loaded event loop by probing wether any of the following modules is |
79 | loaded event loop by probing whether any of the following modules is |
80 | loaded: L<Coro::EV>, L<Coro::Event>, L<EV>, L<Event>, L<Glib>, L<Tk>. The |
80 | loaded: L<Coro::EV>, L<Coro::Event>, L<EV>, L<Event>, L<Glib>, L<Tk>. The |
81 | first one found is used. If none are found, the module tries to load these |
81 | first one found is used. If none are found, the module tries to load these |
82 | modules in the order given. The first one that could be successfully |
82 | modules in the order given. The first one that could be successfully |
83 | loaded will be used. If still none could be found, AnyEvent will fall back |
83 | loaded will be used. If still none could be found, AnyEvent will fall back |
84 | to a pure-perl event loop, which is also not very efficient. |
84 | to a pure-perl event loop, which is also not very efficient. |
… | |
… | |
181 | immediately. |
181 | immediately. |
182 | |
182 | |
183 | Not all event models support a blocking wait - some die in that case |
183 | Not 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 |
185 | are using this from a module, never require a blocking wait>, but let the |
185 | are using this from a module, never require a blocking wait>, but let the |
186 | caller decide wether the call will block or not (for example, by coupling |
186 | caller decide whether the call will block or not (for example, by coupling |
187 | condition variables with some kind of request results and supporting |
187 | condition variables with some kind of request results and supporting |
188 | callbacks so the caller knows that getting the result will not block, |
188 | callbacks so the caller knows that getting the result will not block, |
189 | while still suppporting blocking waits if the caller so desires). |
189 | while still suppporting blocking waits if the caller so desires). |
190 | |
190 | |
191 | Another reason I<never> to C<< ->wait >> in a module is that you cannot |
191 | Another 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 | |
630 | The actual code goes further and collects all errors (C<die>s, exceptions) |
630 | The actual code goes further and collects all errors (C<die>s, exceptions) |
631 | that occured during request processing. The C<result> method detects |
631 | that occured during request processing. The C<result> method detects |
632 | wether an exception as thrown (it is stored inside the $txn object) |
632 | whether an exception as thrown (it is stored inside the $txn object) |
633 | and just throws the exception, which means connection errors and other |
633 | and just throws the exception, which means connection errors and other |
634 | problems get reported tot he code that tries to use the result, not in a |
634 | problems get reported tot he code that tries to use the result, not in a |
635 | random callback. |
635 | random callback. |
636 | |
636 | |
637 | All of this enables the following usage styles: |
637 | All of this enables the following usage styles: |