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

Comparing AnyEvent/README (file contents):
Revision 1.6 by root, Wed Nov 1 01:22:19 2006 UTC vs.
Revision 1.11 by root, Tue Nov 6 16:42:05 2007 UTC

84 chomp (my $input = <STDIN>); 84 chomp (my $input = <STDIN>);
85 warn "read: $input\n"; 85 warn "read: $input\n";
86 undef $w; 86 undef $w;
87 }); 87 });
88 88
89 TIMER WATCHERS 89 TIME WATCHERS
90 You can create a timer watcher by calling the "AnyEvent->timer" method 90 You can create a time watcher by calling the "AnyEvent->timer" method
91 with the following mandatory arguments: 91 with the following mandatory arguments:
92 92
93 "after" after how many seconds (fractions are supported) should the 93 "after" after how many seconds (fractions are supported) should the
94 timer activate. "cb" the callback to invoke. 94 timer activate. "cb" the callback to invoke.
95 95
145 # or socket watcher the calls $result_ready->broadcast 145 # or socket watcher the calls $result_ready->broadcast
146 # when the "result" is ready. 146 # when the "result" is ready.
147 147
148 $result_ready->wait; 148 $result_ready->wait;
149 149
150 SIGNAL WATCHERS
151 You can listen for signals using a signal watcher, "signal" is the
152 signal *name* without any "SIG" prefix. Multiple signals events can be
153 clumped together into one callback invocation, and callback invocation
154 might or might not be asynchronous.
155
156 These watchers might use %SIG, so programs overwriting those signals
157 directly will likely not work correctly.
158
159 Example: exit on SIGINT
160
161 my $w = AnyEvent->signal (signal => "INT", cb => sub { exit 1 });
162
163 CHILD PROCESS WATCHERS
164 You can also listen for the status of a child process specified by the
165 "pid" argument (or any child if the pid argument is 0). The watcher will
166 trigger as often as status change for the child are received. This works
167 by installing a signal handler for "SIGCHLD". The callback will be
168 called with the pid and exit status (as returned by waitpid).
169
170 Example: wait for pid 1333
171
172 my $w = AnyEvent->child (pid => 1333, cb => sub { warn "exit status $?" });
173
174GLOBALS
175 $AnyEvent::MODEL
176 Contains "undef" until the first watcher is being created. Then it
177 contains the event model that is being used, which is the name of
178 the Perl class implementing the model. This class is usually one of
179 the "AnyEvent::Impl:xxx" modules, but can be any other class in the
180 case AnyEvent has been extended at runtime (e.g. in *rxvt-unicode*).
181
182 The known classes so far are:
183
184 EV::AnyEvent based on EV (an interface to libev, best choice)
185 AnyEvent::Impl::Coro based on Coro::Event, second best choice.
186 AnyEvent::Impl::Event based on Event, also second best choice :)
187 AnyEvent::Impl::Glib based on Glib, second-best choice.
188 AnyEvent::Impl::Tk based on Tk, very bad choice.
189 AnyEvent::Impl::Perl pure-perl implementation, inefficient.
190
191 AnyEvent::detect
192 Returns $AnyEvent::MODEL, forcing autodetection of the event model
193 if necessary. You should only call this function right before you
194 would have created an AnyEvent watcher anyway, that is, very late at
195 runtime.
196
150WHAT TO DO IN A MODULE 197WHAT TO DO IN A MODULE
151 As a module author, you should "use AnyEvent" and call AnyEvent methods 198 As a module author, you should "use AnyEvent" and call AnyEvent methods
152 freely, but you should not load a specific event module or rely on it. 199 freely, but you should not load a specific event module or rely on it.
153 200
154 Be careful when you create watchers in the module body - Anyevent will 201 Be careful when you create watchers in the module body - Anyevent will
191 This tells AnyEvent to (literally) use the "urxvt::anyevent::" 238 This tells AnyEvent to (literally) use the "urxvt::anyevent::"
192 package/class when it finds the "urxvt" package/module is loaded. When 239 package/class when it finds the "urxvt" package/module is loaded. When
193 AnyEvent is loaded and asked to find a suitable event model, it will 240 AnyEvent is loaded and asked to find a suitable event model, it will
194 first check for the presence of urxvt. 241 first check for the presence of urxvt.
195 242
196 The class should prove implementations for all watcher types (see 243 The class should provide implementations for all watcher types (see
197 AnyEvent::Impl::Event (source code), AnyEvent::Impl::Glib (Source code) 244 AnyEvent::Impl::Event (source code), AnyEvent::Impl::Glib (Source code)
198 and so on for actual examples, use "perldoc -m AnyEvent::Impl::Glib" to 245 and so on for actual examples, use "perldoc -m AnyEvent::Impl::Glib" to
199 see the sources). 246 see the sources).
200 247
201 The above isn't fictitious, the *rxvt-unicode* (a.k.a. urxvt) uses the 248 The above isn't fictitious, the *rxvt-unicode* (a.k.a. urxvt) uses the
205 *rxvt-unicode* distribution. 252 *rxvt-unicode* distribution.
206 253
207 *rxvt-unicode* also cheats a bit by not providing blocking access to 254 *rxvt-unicode* also cheats a bit by not providing blocking access to
208 condition variables: code blocking while waiting for a condition will 255 condition variables: code blocking while waiting for a condition will
209 "die". This still works with most modules/usages, and blocking calls 256 "die". This still works with most modules/usages, and blocking calls
210 must not be in an interactive appliation, so it makes sense. 257 must not be in an interactive application, so it makes sense.
211 258
212ENVIRONMENT VARIABLES 259ENVIRONMENT VARIABLES
213 The following environment variables are used by this module: 260 The following environment variables are used by this module:
214 261
215 "PERL_ANYEVENT_VERBOSE" when set to 2 or higher, reports which event 262 "PERL_ANYEVENT_VERBOSE" when set to 2 or higher, reports which event

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines