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

Comparing AnyEvent/README (file contents):
Revision 1.75 by root, Thu Jul 16 12:48:38 2015 UTC vs.
Revision 1.78 by root, Sat Jul 1 15:48:51 2017 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
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.
825 829
826SUPPORTED EVENT LOOPS/BACKENDS 830SUPPORTED EVENT LOOPS/BACKENDS
827 The available backend classes are (every class has its own manpage): 831 The available backend classes are (every class has its own manpage):
828 832
829 Backends that are autoprobed when no other event loop can be found. 833 Backends that are autoprobed when no other event loop can be found.
910 $guard = AnyEvent::post_detect { BLOCK } 914 $guard = AnyEvent::post_detect { BLOCK }
911 Arranges for the code block to be executed as soon as the event 915 Arranges for the code block to be executed as soon as the event
912 model is autodetected (or immediately if that has already happened). 916 model is autodetected (or immediately if that has already happened).
913 917
914 The block will be executed *after* the actual backend has been 918 The block will be executed *after* the actual backend has been
915 detected ($AnyEvent::MODEL is set), but *before* any watchers have 919 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 920 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. 921 sources of AnyEvent::AIO to see how this is used.
919 922
920 The most common usage is to create some global watchers, without 923 The most common usage is to create some global watchers, without
921 forcing event module detection too early, for example, AnyEvent::AIO 924 forcing event module detection too early. For example, AnyEvent::AIO
922 creates and installs the global IO::AIO watcher in a "post_detect" 925 creates and installs the global IO::AIO watcher in a "post_detect"
923 block to avoid autodetecting the event module at load time. 926 block to avoid autodetecting the event module at load time.
924 927
925 If called in scalar or list context, then it creates and returns an 928 If called in scalar or list context, then it creates and returns an
926 object that automatically removes the callback again when it is 929 object that automatically removes the callback again when it is
942 # able to just C<undef $WATCHER> if the watcher causes them grief. 945 # able to just C<undef $WATCHER> if the watcher causes them grief.
943 946
944 $WATCHER ||= $guard; 947 $WATCHER ||= $guard;
945 948
946 @AnyEvent::post_detect 949 @AnyEvent::post_detect
947 If there are any code references in this array (you can "push" to it 950 This is a lower level interface then "AnyEvent::post_detect" (the
948 before or after loading AnyEvent), then they will be called directly 951 function). This variable is mainly useful for modules that can do
952 something useful when AnyEvent is used and thus want to know when it
953 is initialised, but do not need to even load it by default. This
954 array provides the means to hook into AnyEvent passively, without
955 loading it.
956
957 Here is how it works: If there are any code references in this array
958 (you can "push" to it before or after loading AnyEvent), then they
949 after the event loop has been chosen. 959 will be called directly after the event loop has been chosen.
950 960
951 You should check $AnyEvent::MODEL before adding to this array, 961 You should check $AnyEvent::MODEL before adding to this array,
952 though: if it is defined then the event loop has already been 962 though: if it is defined then the event loop has already been
953 detected, and the array will be ignored. 963 detected, and the array will be ignored.
954 964
955 Best use "AnyEvent::post_detect { BLOCK }" when your application 965 Best use "AnyEvent::post_detect { BLOCK }" when your application
956 allows it, as it takes care of these details. 966 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 967
964 Example: To load Coro::AnyEvent whenever Coro and AnyEvent are used 968 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 969 together, you could put this into Coro (this is the actual code used
966 by Coro to accomplish this): 970 by Coro to accomplish this):
967 971
1608 my $txn = shift; 1612 my $txn = shift;
1609 my $data = $txn->result; 1613 my $data = $txn->result;
1610 ... 1614 ...
1611 }); 1615 });
1612 1616
1613 EV::loop; 1617 EV::run;
1614 1618
1615 3b. The module user could use AnyEvent, too: 1619 3b. The module user could use AnyEvent, too:
1616 1620
1617 use AnyEvent; 1621 use AnyEvent;
1618 1622

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines