ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/README
(Generate patch)

Comparing AnyEvent/README (file contents):
Revision 1.74 by root, Sat May 2 14:39:31 2015 UTC vs.
Revision 1.79 by root, Tue Feb 26 02:08:34 2019 UTC

812 $bool = $cv->ready 812 $bool = $cv->ready
813 Returns true when the condition is "true", i.e. whether "send" or 813 Returns true when the condition is "true", i.e. whether "send" or
814 "croak" have been called. 814 "croak" have been called.
815 815
816 $cb = $cv->cb ($cb->($cv)) 816 $cb = $cv->cb ($cb->($cv))
817 This is a mutator function that returns the callback set and 817 This is a mutator function that returns the callback set (or "undef"
818 optionally replaces it before doing so. 818 if not) and optionally replaces it before doing so.
819 819
820 The callback will be called when the condition becomes "true", i.e. 820 The callback will be called when the condition becomes "true", i.e.
821 when "send" or "croak" are called, with the only argument being the 821 when "send" or "croak" are called, with the only argument being the
822 condition variable itself. If the condition is already true, the 822 condition variable itself. If the condition is already true, the
823 callback is called immediately when it is set. Calling "recv" inside 823 callback is called immediately when it is set. Calling "recv" inside
824 the callback or at any later time is guaranteed not to block. 824 the callback or at any later time is guaranteed not to block.
825 825
826 Additionally, when the callback is invoked, it is also removed from
827 the condvar (reset to "undef"), so the condvar does not keep a
828 reference to the callback after invocation.
829
826SUPPORTED EVENT LOOPS/BACKENDS 830SUPPORTED EVENT LOOPS/BACKENDS
827 The available backend classes are (every class has its own manpage): 831 The following backend classes are part of the AnyEvent distribution
832 (every class has its own manpage):
828 833
829 Backends that are autoprobed when no other event loop can be found. 834 Backends that are autoprobed when no other event loop can be found.
830 EV is the preferred backend when no other event loop seems to be in 835 EV is the preferred backend when no other event loop seems to be in
831 use. If EV is not installed, then AnyEvent will fall back to its own 836 use. If EV is not installed, then AnyEvent will fall back to its own
832 pure-perl implementation, which is available everywhere as it comes 837 pure-perl implementation, which is available everywhere as it comes
877 882
878 AnyEvent knows about both Prima and Wx, however, and will try to 883 AnyEvent knows about both Prima and Wx, however, and will try to
879 load POE when detecting them, in the hope that POE will pick them 884 load POE when detecting them, in the hope that POE will pick them
880 up, in which case everything will be automatic. 885 up, in which case everything will be automatic.
881 886
887 Known event loops outside the AnyEvent distribution
888 The following event loops or programs support AnyEvent by providing
889 their own AnyEvent backend. They will be picked up automatically.
890
891 urxvt::anyevent available to rxvt-unicode extensions
892
882GLOBAL VARIABLES AND FUNCTIONS 893GLOBAL VARIABLES AND FUNCTIONS
883 These are not normally required to use AnyEvent, but can be useful to 894 These are not normally required to use AnyEvent, but can be useful to
884 write AnyEvent extension modules. 895 write AnyEvent extension modules.
885 896
886 $AnyEvent::MODEL 897 $AnyEvent::MODEL
910 $guard = AnyEvent::post_detect { BLOCK } 921 $guard = AnyEvent::post_detect { BLOCK }
911 Arranges for the code block to be executed as soon as the event 922 Arranges for the code block to be executed as soon as the event
912 model is autodetected (or immediately if that has already happened). 923 model is autodetected (or immediately if that has already happened).
913 924
914 The block will be executed *after* the actual backend has been 925 The block will be executed *after* the actual backend has been
915 detected ($AnyEvent::MODEL is set), but *before* any watchers have 926 detected ($AnyEvent::MODEL is set), so it is possible to do some
916 been created, so it is possible to e.g. patch @AnyEvent::ISA or do 927 initialisation only when AnyEvent is actually initialised - see the
917 other initialisations - see the sources of AnyEvent::Strict or
918 AnyEvent::AIO to see how this is used. 928 sources of AnyEvent::AIO to see how this is used.
919 929
920 The most common usage is to create some global watchers, without 930 The most common usage is to create some global watchers, without
921 forcing event module detection too early, for example, AnyEvent::AIO 931 forcing event module detection too early. For example, AnyEvent::AIO
922 creates and installs the global IO::AIO watcher in a "post_detect" 932 creates and installs the global IO::AIO watcher in a "post_detect"
923 block to avoid autodetecting the event module at load time. 933 block to avoid autodetecting the event module at load time.
924 934
925 If called in scalar or list context, then it creates and returns an 935 If called in scalar or list context, then it creates and returns an
926 object that automatically removes the callback again when it is 936 object that automatically removes the callback again when it is
942 # able to just C<undef $WATCHER> if the watcher causes them grief. 952 # able to just C<undef $WATCHER> if the watcher causes them grief.
943 953
944 $WATCHER ||= $guard; 954 $WATCHER ||= $guard;
945 955
946 @AnyEvent::post_detect 956 @AnyEvent::post_detect
947 If there are any code references in this array (you can "push" to it 957 This is a lower level interface then "AnyEvent::post_detect" (the
948 before or after loading AnyEvent), then they will be called directly 958 function). This variable is mainly useful for modules that can do
959 something useful when AnyEvent is used and thus want to know when it
960 is initialised, but do not need to even load it by default. This
961 array provides the means to hook into AnyEvent passively, without
962 loading it.
963
964 Here is how it works: If there are any code references in this array
965 (you can "push" to it before or after loading AnyEvent), then they
949 after the event loop has been chosen. 966 will be called directly after the event loop has been chosen.
950 967
951 You should check $AnyEvent::MODEL before adding to this array, 968 You should check $AnyEvent::MODEL before adding to this array,
952 though: if it is defined then the event loop has already been 969 though: if it is defined then the event loop has already been
953 detected, and the array will be ignored. 970 detected, and the array will be ignored.
954 971
955 Best use "AnyEvent::post_detect { BLOCK }" when your application 972 Best use "AnyEvent::post_detect { BLOCK }" when your application
956 allows it, as it takes care of these details. 973 allows it, as it takes care of these details.
957
958 This variable is mainly useful for modules that can do something
959 useful when AnyEvent is used and thus want to know when it is
960 initialised, but do not need to even load it by default. This array
961 provides the means to hook into AnyEvent passively, without loading
962 it.
963 974
964 Example: To load Coro::AnyEvent whenever Coro and AnyEvent are used 975 Example: To load Coro::AnyEvent whenever Coro and AnyEvent are used
965 together, you could put this into Coro (this is the actual code used 976 together, you could put this into Coro (this is the actual code used
966 by Coro to accomplish this): 977 by Coro to accomplish this):
967 978
1029 1040
1030 If you want to sprinkle loads of logging calls around your code, 1041 If you want to sprinkle loads of logging calls around your code,
1031 consider creating a logger callback with the "AnyEvent::Log::logger" 1042 consider creating a logger callback with the "AnyEvent::Log::logger"
1032 function, which can reduce typing, codesize and can reduce the 1043 function, which can reduce typing, codesize and can reduce the
1033 logging overhead enourmously. 1044 logging overhead enourmously.
1045
1046 AnyEvent::fh_block $filehandle
1047 AnyEvent::fh_unblock $filehandle
1048 Sets blocking or non-blocking behaviour for the given filehandle.
1034 1049
1035WHAT TO DO IN A MODULE 1050WHAT TO DO IN A MODULE
1036 As a module author, you should "use AnyEvent" and call AnyEvent methods 1051 As a module author, you should "use AnyEvent" and call AnyEvent methods
1037 freely, but you should not load a specific event module or rely on it. 1052 freely, but you should not load a specific event module or rely on it.
1038 1053
1604 my $txn = shift; 1619 my $txn = shift;
1605 my $data = $txn->result; 1620 my $data = $txn->result;
1606 ... 1621 ...
1607 }); 1622 });
1608 1623
1609 EV::loop; 1624 EV::run;
1610 1625
1611 3b. The module user could use AnyEvent, too: 1626 3b. The module user could use AnyEvent, too:
1612 1627
1613 use AnyEvent; 1628 use AnyEvent;
1614 1629

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines