… | |
… | |
87 | use Async::Interrupt (); |
87 | use Async::Interrupt (); |
88 | |
88 | |
89 | use base 'EV::Loop'; |
89 | use base 'EV::Loop'; |
90 | |
90 | |
91 | BEGIN { |
91 | BEGIN { |
92 | our $VERSION = '0.02'; |
92 | our $VERSION = '1.01'; |
93 | |
93 | |
94 | require XSLoader; |
94 | require XSLoader; |
95 | XSLoader::load ("EV::Loop::Async", $VERSION); |
95 | XSLoader::load ("EV::Loop::Async", $VERSION); |
96 | } |
96 | } |
97 | |
97 | |
… | |
… | |
133 | $EV::Loop::Async::INTERRUPT->scope_block; |
133 | $EV::Loop::Async::INTERRUPT->scope_block; |
134 | # no default loop callbacks will be executed here. |
134 | # no default loop callbacks will be executed here. |
135 | # the loop will not be locked, however. |
135 | # the loop will not be locked, however. |
136 | } |
136 | } |
137 | |
137 | |
|
|
138 | Example: embed the default EV::Async::Loop loop into the default L<EV> |
|
|
139 | loop (note that it could be any other event loop as well). |
|
|
140 | |
|
|
141 | my $async_w = EV::io |
|
|
142 | $EV::Loop::Async::LOOP->interrupt->pipe_fileno, |
|
|
143 | EV::READ, |
|
|
144 | sub { }; |
|
|
145 | |
138 | =item $loop = new EV::Loop::Async $flags, [Async-Interrupt-Arguments...] |
146 | =item $loop = new EV::Loop::Async $flags, [Async-Interrupt-Arguments...] |
139 | |
147 | |
140 | This constructor: |
148 | This constructor: |
141 | |
149 | |
142 | =over 4 |
150 | =over 4 |
… | |
… | |
150 | =item 4. runs C<< $loop->run >> in that thread. |
158 | =item 4. runs C<< $loop->run >> in that thread. |
151 | |
159 | |
152 | =back |
160 | =back |
153 | |
161 | |
154 | The resulting loop will be running and unlocked when it is returned. |
162 | The resulting loop will be running and unlocked when it is returned. |
|
|
163 | |
|
|
164 | Example: create a new loop, block it's interrupt object and embed |
|
|
165 | it into the foreground L<AnyEvent> event loop. This basically runs the |
|
|
166 | C<EV::Loop::Async> loop in a synchronous way inside another loop. |
|
|
167 | |
|
|
168 | my $loop = new EV::Loop::Async 0; |
|
|
169 | my $async = $loop->interrupt; |
|
|
170 | |
|
|
171 | $async->block; |
|
|
172 | |
|
|
173 | my $async_w = AnyEvent->io ( |
|
|
174 | fh => $async->pipe_fileno, |
|
|
175 | poll => "r", |
|
|
176 | cb => sub { |
|
|
177 | # temporarily unblock to handle events |
|
|
178 | $async->unblock; |
|
|
179 | $async->block; |
|
|
180 | }, |
|
|
181 | ); |
155 | |
182 | |
156 | =cut |
183 | =cut |
157 | |
184 | |
158 | sub new { |
185 | sub new { |
159 | my ($class, $flags, @asy) = @_; |
186 | my ($class, $flags, @asy) = @_; |
160 | |
187 | |
161 | my $self = bless $class->SUPER::new ($flags), $class; |
188 | my $self = bless $class->SUPER::new ($flags), $class; |
162 | my ($c_func, $c_arg) = _c_func $self; |
189 | my ($c_func, $c_arg) = _c_func $self; |
163 | my $asy = new Async::Interrupt @asy, c_cb => [$c_func, $c_arg]; |
190 | my $asy = new Async::Interrupt @asy, c_cb => [$c_func, $c_arg]; |
164 | $self->_attach ($asy, $asy->signal_func); |
191 | _attach $self, $asy, $asy->signal_func; |
165 | |
192 | |
166 | $self |
193 | $self |
167 | } |
194 | } |
168 | |
195 | |
169 | =item $loop->notify |
196 | =item $loop->notify |
… | |
… | |
217 | =item $loop->scope_lock |
244 | =item $loop->scope_lock |
218 | |
245 | |
219 | Calls C<lock> immediately, and C<unlock> automatically whent he current |
246 | Calls C<lock> immediately, and C<unlock> automatically whent he current |
220 | scope is left. |
247 | scope is left. |
221 | |
248 | |
|
|
249 | =item $loop->set_max_foreground_loops ($max_loops) |
|
|
250 | |
|
|
251 | The background loop will immediately stop polling for new events after it |
|
|
252 | has collected at least one new event, regardless of how long it then takes |
|
|
253 | to actually handle them. |
|
|
254 | |
|
|
255 | When Perl finally handles the events, there could be many more ready |
|
|
256 | file descriptors. To improve latency and performance, you can ask |
|
|
257 | C<EV::Loop::Async> to loop an additional number of times in the foreground |
|
|
258 | after invoking the callbacks, effectively doing the polling in the |
|
|
259 | foreground. |
|
|
260 | |
|
|
261 | The default is C<0>, meaning that no foreground polling will be done. A |
|
|
262 | value of C<1> means that, after handling the pending events, it will call |
|
|
263 | C<< $loop->loop (EV::LOOP_NONBLOCK) >> and handle the resulting events, if |
|
|
264 | any. A value of C<2> means that this will be iterated twice. |
|
|
265 | |
|
|
266 | When a foreground event poll does not yield any new events, then no |
|
|
267 | further iterations will be made, so this is only a I<maximum> value of |
|
|
268 | additional loop runs. |
|
|
269 | |
|
|
270 | Take also note of the standard EV C<set_io_collect_interval> |
|
|
271 | functionality, which can achieve a similar, but different, effect - YMMV. |
|
|
272 | |
222 | =back |
273 | =back |
223 | |
274 | |
224 | =head1 SEE ALSO |
275 | =head1 SEE ALSO |
225 | |
276 | |
226 | L<EV>, L<Async::Interrupt>. |
277 | L<EV>, L<Async::Interrupt>. |