Select(3pm)
β¨ Select(3pm) β¨
okay bestie, gather round, because we're talking about Coro::Select β a slow but coro-aware glow-up replacement for CORE::select π
and honestly? she's doing the lord's work.
π¦ 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
like, pick your fighter, i guess πΈ
π DESCRIPTION π
so this module is literally trying to build a fully working replacement for perl's built-in select, except it does the whole thing with AnyEvent watchers, which means other threads can keep running in parallel to whoever's sitting there selecting. and the way that SO many libraries out there only ship a blocking API, they don't use globals, and they reach for select (or IO::Select) constantly β so this effectively makes most of those libraries "somewhat" non-blocking with respect to other threads. not perfect, but iconic behaviour, no cap π«Ά
ngl, this implementation is at her absolute fastest when there are only very few bits set in the fd set(s). tiny bit energy, max speed β
okay so the tea β β if you want this to work globally, you have to use it before any other module that uses select, so realistically it should be the first module you use in your main program. periodt.
β οΈ but lowkey be careful, because overridingselectglobally can genuinely cause problems: someAnyEventbackends useselectthemselves, and asking AnyEvent to use Coro::Select, which then asks AnyEvent β yeah, that will not quite work. it's giving ouroboros. it's giving circular dependency. π
you can also summon it straight from the commandline as perl -MCoro::Select β¨
if you only wanna override select for one single module (say, Net::DBus::Reactor), you load it with a code fragment like this:
{
package Net::DBus::Reactor;
use Coro::Select qw(select);
use Net::DBus::Reactor;
}
okay but here's the drama: some modules β notably POE::Loop::Select β are out here calling CORE::select directly, completely bypassing the vibe. for those, we have to patch the opcode table by sandwiching it between calls to Coro::Select::patch_pp_sselect and Coro::Select::unpatch_pp_sselect, like so:
BEGIN {
use Coro::Select ();
Coro::Select::patch_pp_sselect;
require evil_poe_module_using_CORE::SELECT;
Coro::Select::unpatch_pp_sselect;
}
see that evil_poe_module_using_CORE::SELECT? yeah. she said what she said π
π BUGS π
for performance reasons, Coro::Select's select function might not properly detect bad file descriptors β but tbh relying on EBADF is inherently non-portable anyway, so like... π€·βοΈ
π SEE ALSO π
Coro::LWPβ go look, bestie π
π AUTHOR/SUPPORT/CONTACT π
Marc A. Lehmann <schmorp@schmorp.de>
http://software.schmorp.de/pkg/Coro.html
and that's the whole page, babes π this lil gem is perl v5.40.1, dated 2025-03-21, filed under Select(3pm) β thanks for coming to my ted talk, mwah π§π
π¦ where this page comes from
- debian trixie: libcoro-perl 6.570-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libcoro-perl 6.570-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms