EV-Loop-Async
view release on metacpan or search on metacpan
{
$loop->scope_lock; # lock the loop structures
$timer->stop;
# no need to notify
}
=head1 DESCRIPTION
This module implements a rather specialised event loop - it takes a normal
L<EV> event loop and runs it in a separate thread. That means it will poll
for events even while your foreground Perl interpreter is busy (you don't
need to have perls pseudo-threads enabled for this either).
Whenever the event loop detecs new events, it will interrupt perl and ask
it to invoke all the pending watcher callbacks. This invocation will be
"synchronous" (in the perl thread), but it can happen at any time.
See the documentation for L<Async::Interrupt> for details on when and how
your perl program can be interrupted (and how to avoid it), and how to
integrate background event loops into foreground ones.
watcher(s) (which only happens when it iterates, which you can force by
calling this method).
Without calling this method, the event loop I<eventually> takes notice
of new watchers, bit when this happens is not well-defined (can be
instantaneous, or take a few hours).
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;
}
# stop the timer watcher again - locking is required once more
{
$loop->scope_lock; # lock the loop structures
$timer->stop;
# no need to notify
}
DESCRIPTION
This module implements a rather specialised event loop - it takes a
normal EV event loop and runs it in a separate thread. That means it
will poll for events even while your foreground Perl interpreter is busy
(you don't need to have perls pseudo-threads enabled for this either).
Whenever the event loop detecs new events, it will interrupt perl and
ask it to invoke all the pending watcher callbacks. This invocation will
be "synchronous" (in the perl thread), but it can happen at any time.
See the documentation for Async::Interrupt for details on when and how
your perl program can be interrupted (and how to avoid it), and how to
integrate background event loops into foreground ones.
new watcher(s) (which only happens when it iterates, which you can
force by calling this method).
Without calling this method, the event loop *eventually* takes
notice of new watchers, bit when this happens is not well-defined
(can be instantaneous, or take a few hours).
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;
}
( run in 0.603 second using v1.01-cache-2.11-cpan-87723dcf8b7 )