EV-Loop-Async
view release on metacpan or search on metacpan
No locking is required.
Example: lock the loop, create a timer, nudge the loop so it takes notice
of the new timer, then evily busy-wait till the timer fires.
my $timer;
my $flag;
{
$loop->scope_lock;
$timer = $loop->timer (1, 0, sub { $flag = 1 });
$loop->notify;
}
1 until $flag;
=item $loop->lock
=item $loop->unlock
Lock/unlock the loop data structures. Since the event loop runs in
a separate thread, you have to lock the loop data structures before
accessing them in any way. Since I was lazy, you have to do this manually.
You must lock under the same conditions as you would have to lock the
underlying C library, e.g. when starting or stopping watchers (but not
when creating or destroying them, but note that create and destroy often
starts and stops for you, in which case you have to lock).
When in doubt, lock.
See also the next method, C<< $loop->scope_lock >> for a more failsafe way
to lock parts of your code.
Note that there must be exactly one call of "unblock" for every previous
call to "block" (i.e. calls can nest).
=item $loop->scope_lock
Calls C<lock> immediately, and C<unlock> automatically whent he current
scope is left.
=item $loop->set_max_foreground_loops ($max_loops)
The background loop will immediately stop polling for new events after it
has collected at least one new event, regardless of how long it then takes
to actually handle them.
When Perl finally handles the events, there could be many more ready
file descriptors. To improve latency and performance, you can ask
C<EV::Loop::Async> to loop an additional number of times in the foreground
after invoking the callbacks, effectively doing the polling in the
foreground.
The default is C<0>, meaning that no foreground polling will be done. A
value of C<1> means that, after handling the pending events, it will call
C<< $loop->loop (EV::LOOP_NONBLOCK) >> and handle the resulting events, if
any. A value of C<2> means that this will be iterated twice.
When a foreground event poll does not yield any new events, then no
further iterations will be made, so this is only a I<maximum> value of
additional loop runs.
Take also note of the standard EV C<set_io_collect_interval>
functionality, which can achieve a similar, but different, effect - YMMV.
=back
=head1 SEE ALSO
L<EV>, L<Async::Interrupt>.
=head1 AUTHOR
Marc Lehmann <schmorp@schmorp.de>
http://home.schmorp.de/
=cut
1
( run in 0.369 second using v1.01-cache-2.11-cpan-71847e10f99 )