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.132 by root, Sun May 25 01:05:27 2008 UTC vs.
Revision 1.135 by root, Sun May 25 04:49:01 2008 UTC

312C<cb>, which specifies a callback to be called when the condition variable 312C<cb>, which specifies a callback to be called when the condition variable
313becomes true. 313becomes true.
314 314
315After creation, the condition variable is "false" until it becomes "true" 315After creation, the condition variable is "false" until it becomes "true"
316by calling the C<send> method (or calling the condition variable as if it 316by calling the C<send> method (or calling the condition variable as if it
317were a callback). 317were a callback, read about the caveats in the description for the C<<
318->send >> method).
318 319
319Condition variables are similar to callbacks, except that you can 320Condition variables are similar to callbacks, except that you can
320optionally wait for them. They can also be called merge points - points 321optionally wait for them. They can also be called merge points - points
321in time where multiple outstanding events have been processed. And yet 322in time where multiple outstanding events have been processed. And yet
322another way to call them is transactions - each condition variable can be 323another way to call them is transactions - each condition variable can be
394immediately from within send. 395immediately from within send.
395 396
396Any arguments passed to the C<send> call will be returned by all 397Any arguments passed to the C<send> call will be returned by all
397future C<< ->recv >> calls. 398future C<< ->recv >> calls.
398 399
399Condition variables are overloaded so one can call them directly (as a 400Condition variables are overloaded so one can call them directly
400code reference). Calling them directly is the same as calling C<send>. 401(as a code reference). Calling them directly is the same as calling
402C<send>. Note, however, that many C-based event loops do not handle
403overloading, so as tempting as it may be, passing a condition variable
404instead of a callback does not work. Both the pure perl and EV loops
405support overloading, however, as well as all functions that use perl to
406invoke a callback (as in L<AnyEvent::Socket> and L<AnyEvent::DNS> for
407example).
401 408
402=item $cv->croak ($error) 409=item $cv->croak ($error)
403 410
404Similar to send, but causes all call's to C<< ->recv >> to invoke 411Similar to send, but causes all call's to C<< ->recv >> to invoke
405C<Carp::croak> with the given error message/object/scalar. 412C<Carp::croak> with the given error message/object/scalar.
612 619
613If it doesn't care, it can just "use AnyEvent" and use it itself, or not 620If it doesn't care, it can just "use AnyEvent" and use it itself, or not
614do anything special (it does not need to be event-based) and let AnyEvent 621do anything special (it does not need to be event-based) and let AnyEvent
615decide which implementation to chose if some module relies on it. 622decide which implementation to chose if some module relies on it.
616 623
617If the main program relies on a specific event model. For example, in 624If the main program relies on a specific event model - for example, in
618Gtk2 programs you have to rely on the Glib module. You should load the 625Gtk2 programs you have to rely on the Glib module - you should load the
619event module before loading AnyEvent or any module that uses it: generally 626event module before loading AnyEvent or any module that uses it: generally
620speaking, you should load it as early as possible. The reason is that 627speaking, you should load it as early as possible. The reason is that
621modules might create watchers when they are loaded, and AnyEvent will 628modules might create watchers when they are loaded, and AnyEvent will
622decide on the event model to use as soon as it creates watchers, and it 629decide on the event model to use as soon as it creates watchers, and it
623might chose the wrong one unless you load the correct one yourself. 630might chose the wrong one unless you load the correct one yourself.
624 631
625You can chose to use a rather inefficient pure-perl implementation by 632You can chose to use a pure-perl implementation by loading the
626loading the C<AnyEvent::Impl::Perl> module, which gives you similar 633C<AnyEvent::Impl::Perl> module, which gives you similar behaviour
627behaviour everywhere, but letting AnyEvent chose is generally better. 634everywhere, but letting AnyEvent chose the model is generally better.
635
636=head2 MAINLOOP EMULATION
637
638Sometimes (often for short test scripts, or even standalone programs who
639only want to use AnyEvent), you do not want to run a specific event loop.
640
641In that case, you can use a condition variable like this:
642
643 AnyEvent->condvar->recv;
644
645This has the effect of entering the event loop and looping forever.
646
647Note that usually your program has some exit condition, in which case
648it is better to use the "traditional" approach of storing a condition
649variable somewhere, waiting for it, and sending it when the program should
650exit cleanly.
651
628 652
629=head1 OTHER MODULES 653=head1 OTHER MODULES
630 654
631The following is a non-exhaustive list of additional modules that use 655The following is a non-exhaustive list of additional modules that use
632AnyEvent and can therefore be mixed easily with other AnyEvent modules 656AnyEvent and can therefore be mixed easily with other AnyEvent modules
648 672
649Provides various utility functions for (internet protocol) sockets, 673Provides various utility functions for (internet protocol) sockets,
650addresses and name resolution. Also functions to create non-blocking tcp 674addresses and name resolution. Also functions to create non-blocking tcp
651connections or tcp servers, with IPv6 and SRV record support and more. 675connections or tcp servers, with IPv6 and SRV record support and more.
652 676
677=item L<AnyEvent::DNS>
678
679Provides rich asynchronous DNS resolver capabilities.
680
653=item L<AnyEvent::HTTPD> 681=item L<AnyEvent::HTTPD>
654 682
655Provides a simple web application server framework. 683Provides a simple web application server framework.
656
657=item L<AnyEvent::DNS>
658
659Provides rich asynchronous DNS resolver capabilities.
660 684
661=item L<AnyEvent::FastPing> 685=item L<AnyEvent::FastPing>
662 686
663The fastest ping in the west. 687The fastest ping in the west.
664 688
713our $MODEL; 737our $MODEL;
714 738
715our $AUTOLOAD; 739our $AUTOLOAD;
716our @ISA; 740our @ISA;
717 741
742our @REGISTRY;
743
718our $verbose = $ENV{PERL_ANYEVENT_VERBOSE}*1; 744our $verbose = $ENV{PERL_ANYEVENT_VERBOSE}*1;
719
720our @REGISTRY;
721 745
722our %PROTOCOL; # (ipv4|ipv6) => (1|2) 746our %PROTOCOL; # (ipv4|ipv6) => (1|2)
723 747
724{ 748{
725 my $idx; 749 my $idx;
728} 752}
729 753
730my @models = ( 754my @models = (
731 [EV:: => AnyEvent::Impl::EV::], 755 [EV:: => AnyEvent::Impl::EV::],
732 [Event:: => AnyEvent::Impl::Event::], 756 [Event:: => AnyEvent::Impl::Event::],
733 [Tk:: => AnyEvent::Impl::Tk::],
734 [Wx:: => AnyEvent::Impl::POE::],
735 [Prima:: => AnyEvent::Impl::POE::],
736 [AnyEvent::Impl::Perl:: => AnyEvent::Impl::Perl::], 757 [AnyEvent::Impl::Perl:: => AnyEvent::Impl::Perl::],
737 # everything below here will not be autoprobed as the pureperl backend should work everywhere 758 # everything below here will not be autoprobed
738 [Glib:: => AnyEvent::Impl::Glib::], 759 # as the pureperl backend should work everywhere
760 # and is usually faster
761 [Tk:: => AnyEvent::Impl::Tk::], # crashes with many handles
762 [Glib:: => AnyEvent::Impl::Glib::], # becomes extremely slow with many watchers
739 [Event::Lib:: => AnyEvent::Impl::EventLib::], # too buggy 763 [Event::Lib:: => AnyEvent::Impl::EventLib::], # too buggy
740 [Qt:: => AnyEvent::Impl::Qt::], # requires special main program 764 [Qt:: => AnyEvent::Impl::Qt::], # requires special main program
741 [POE::Kernel:: => AnyEvent::Impl::POE::], # lasciate ogni speranza 765 [POE::Kernel:: => AnyEvent::Impl::POE::], # lasciate ogni speranza
766 [Wx:: => AnyEvent::Impl::POE::],
767 [Prima:: => AnyEvent::Impl::POE::],
742); 768);
743 769
744our %method = map +($_ => 1), qw(io timer signal child condvar one_event DESTROY); 770our %method = map +($_ => 1), qw(io timer signal child condvar one_event DESTROY);
745 771
746our @post_detect; 772our @post_detect;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines