Coro
view release on metacpan or search on metacpan
Coro/Select.pm view on Meta::CPAN
=head1 NAME
Coro::Select - a (slow but coro-aware) replacement for CORE::select
=head1 SYNOPSIS
use Coro::Select; # replace select globally (be careful, see below)
use Core::Select 'select'; # only in this module
use Coro::Select (); # use Coro::Select::select
=head1 DESCRIPTION
This module tries to create a fully working replacement for perl's
C<select> built-in, using C<AnyEvent> watchers to do the job, so other
threads can run in parallel to any select user. As many libraries that
only have a blocking API do not use global variables and often use select
(or IO::Select), this effectively makes most such libraries "somewhat"
non-blocking w.r.t. other threads.
This implementation works fastest when only very few bits are set in the
fd set(s).
To be effective globally, this module must be C<use>'d before any other
module that uses C<select>, so it should generally be the first module
C<use>'d in the main program. Note that overriding C<select> globally
might actually cause problems, as some C<AnyEvent> backends use C<select>
themselves, and asking AnyEvent to use Coro::Select, which in turn asks
AnyEvent will not quite work.
You can also invoke it from the commandline as C<perl -MCoro::Select>.
To override select only for a single module (e.g. C<Net::DBus::Reactor>),
use a code fragment like this to load it:
{
package Net::DBus::Reactor;
use Coro::Select qw(select);
use Net::DBus::Reactor;
}
Some modules (notably L<POE::Loop::Select>) directly call
C<CORE::select>. For these modules, we need to patch the opcode table by
sandwiching it between calls to C<Coro::Select::patch_pp_sselect> and
C<Coro::Select::unpatch_pp_sselect>:
BEGIN {
use Coro::Select ();
Coro::Select::patch_pp_sselect;
require evil_poe_module_using_CORE::SELECT;
Coro::Select::unpatch_pp_sselect;
}
=over 4
=cut
package Coro::Select;
use common::sense;
use Errno;
use Coro ();
( run in 1.271 second using v1.01-cache-2.11-cpan-98e64b0badf )