… | |
… | |
65 | You can create I/O watcher by calling the "AnyEvent->io" method with the |
65 | You can create I/O watcher by calling the "AnyEvent->io" method with the |
66 | following mandatory arguments: |
66 | following mandatory arguments: |
67 | |
67 | |
68 | "fh" the Perl *filehandle* (not filedescriptor) to watch for events. |
68 | "fh" the Perl *filehandle* (not filedescriptor) to watch for events. |
69 | "poll" must be a string that is either "r" or "w", that creates a |
69 | "poll" must be a string that is either "r" or "w", that creates a |
70 | watcher waiting for "r"eadable or "w"ritable events. "cb" teh callback |
70 | watcher waiting for "r"eadable or "w"ritable events. "cb" the callback |
71 | to invoke everytime the filehandle becomes ready. |
71 | to invoke everytime the filehandle becomes ready. |
72 | |
72 | |
73 | Only one io watcher per "fh" and "poll" combination is allowed (i.e. on |
73 | Only one io watcher per "fh" and "poll" combination is allowed (i.e. on |
74 | a socket you can have one r + one w, not any more (limitation comes from |
74 | a socket you can have one r + one w, not any more (limitation comes from |
75 | Tk - if you are sure you are not using Tk this limitation is gone). |
75 | Tk - if you are sure you are not using Tk this limitation is gone). |
… | |
… | |
103 | my $w = AnyEvent->timer (after => 7.7, cb => sub { |
103 | my $w = AnyEvent->timer (after => 7.7, cb => sub { |
104 | warn "timeout\n"; |
104 | warn "timeout\n"; |
105 | }); |
105 | }); |
106 | |
106 | |
107 | # to cancel the timer: |
107 | # to cancel the timer: |
108 | undef $w |
108 | undef $w; |
109 | |
109 | |
110 | CONDITION WATCHERS |
110 | CONDITION WATCHERS |
111 | Condition watchers can be created by calling the "AnyEvent->condvar" |
111 | Condition watchers can be created by calling the "AnyEvent->condvar" |
112 | method without any arguments. |
112 | method without any arguments. |
113 | |
113 | |
… | |
… | |
160 | |
160 | |
161 | my $w = AnyEvent->signal (signal => "INT", cb => sub { exit 1 }); |
161 | my $w = AnyEvent->signal (signal => "INT", cb => sub { exit 1 }); |
162 | |
162 | |
163 | CHILD PROCESS WATCHERS |
163 | CHILD PROCESS WATCHERS |
164 | You can also listen for the status of a child process specified by the |
164 | You can also listen for the status of a child process specified by the |
165 | "pid" argument. The watcher will only trigger once. This works by |
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 |
166 | installing a signal handler for "SIGCHLD". |
167 | by installing a signal handler for "SIGCHLD". The callback will be |
|
|
168 | called with the pid and exit status (as returned by waitpid). |
167 | |
169 | |
168 | Example: wait for pid 1333 |
170 | Example: wait for pid 1333 |
169 | |
171 | |
170 | my $w = AnyEvent->child (pid => 1333, cb => sub { warn "exit status $?" }); |
172 | my $w = AnyEvent->child (pid => 1333, cb => sub { warn "exit status $?" }); |
171 | |
173 | |
… | |
… | |
177 | the "AnyEvent::Impl:xxx" modules, but can be any other class in the |
179 | the "AnyEvent::Impl:xxx" modules, but can be any other class in the |
178 | case AnyEvent has been extended at runtime (e.g. in *rxvt-unicode*). |
180 | case AnyEvent has been extended at runtime (e.g. in *rxvt-unicode*). |
179 | |
181 | |
180 | The known classes so far are: |
182 | The known classes so far are: |
181 | |
183 | |
|
|
184 | AnyEvent::Impl::CoroEV based on Coro::EV, best choice. |
|
|
185 | AnyEvent::Impl::EV based on EV (an interface to libev, also best choice). |
182 | AnyEvent::Impl::Coro based on Coro::Event, best choise. |
186 | AnyEvent::Impl::Coro based on Coro::Event, second best choice. |
183 | AnyEvent::Impl::Event based on Event, also best choice :) |
187 | AnyEvent::Impl::Event based on Event, also second best choice :) |
184 | AnyEvent::Impl::Glib based on Glib, second-best choice. |
188 | AnyEvent::Impl::Glib based on Glib, second-best choice. |
185 | AnyEvent::Impl::Tk based on Tk, very bad choice. |
189 | AnyEvent::Impl::Tk based on Tk, very bad choice. |
186 | AnyEvent::Impl::Perl pure-perl implementation, inefficient. |
190 | AnyEvent::Impl::Perl pure-perl implementation, inefficient. |
187 | |
191 | |
188 | AnyEvent::detect |
192 | AnyEvent::detect |