ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV-Loop-Async/Async.pm
(Generate patch)

Comparing EV-Loop-Async/Async.pm (file contents):
Revision 1.3 by root, Tue Jul 14 15:09:44 2009 UTC vs.
Revision 1.4 by root, Fri Jul 17 02:52:22 2009 UTC

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
138Example: embed the default EV::Async::Loop loop into the default L<EV>
139loop (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
140This constructor: 148This 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
154The resulting loop will be running and unlocked when it is returned. 162The resulting loop will be running and unlocked when it is returned.
163
164Example: create a new loop, block it's interrupt object and embed
165it into the foreground L<AnyEvent> event loop. This basically runs the
166C<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
158sub new { 185sub new {
159 my ($class, $flags, @asy) = @_; 186 my ($class, $flags, @asy) = @_;
217=item $loop->scope_lock 244=item $loop->scope_lock
218 245
219Calls C<lock> immediately, and C<unlock> automatically whent he current 246Calls C<lock> immediately, and C<unlock> automatically whent he current
220scope is left. 247scope is left.
221 248
249=item $loop->set_max_foreground_loops ($max_loops)
250
251The background loop will immediately stop polling for new events after it
252has collected at least one new event, regardless of how long it then takes
253to actually handle them.
254
255When Perl finally handles the events, there could be many more ready
256file descriptors. To improve latency and performance, you can ask
257C<EV::Loop::Async> to loop an additional number of times in the foreground
258after invoking the callbacks, effectively doing the polling in the
259foreground.
260
261The default is C<0>, meaning thatno foreground polling will be done. A
262value of C<1> means that, after handling the pending events, it will call
263C<< $loop->loop (EV::LOOP_NONBLOCK) >> and handle the resulting events, if
264any. A value of C<2> means that this will be iterated twice.
265
266When a foreground event poll does not yield any new events, then no
267further iterations will be made, so this is only a I<maximum> value of
268additional loop runs.
269
222=back 270=back
223 271
224=head1 SEE ALSO 272=head1 SEE ALSO
225 273
226L<EV>, L<Async::Interrupt>. 274L<EV>, L<Async::Interrupt>.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines