IO::As...:Select(3pm)
β¨ IO::Async::Loop::Select β bestie's guide π
okay so this page is from the perl manual, section 3pm, and it's literally called IO::As...:Select(3pm) because the title got truncated by the terminal and nobody fixed it (iconic behaviour honestly). Real name: IO::Async::Loop::Select β it's the class that lets you run IO::Async on top of a plain old select(2) syscall. let's get into it π¦
πΈ NAME πΈ
IO::Async::Loop::Select β use IO::Async with select(2)
β¨ SYNOPSIS β¨
so normally you would not be out here constructing one of these yourself, bestie. BUT. It can genuinely be useful if you want to run IO::Async inside a program that's already doing its own select call. like, you're moving in, and select is already living there. coexisting. roommates. π«Ά
use IO::Async::Loop::Select;
my $loop = IO::Async::Loop::Select->new;
$loop->add( ... );
while(1) {
my ( $rvec, $wvec, $evec ) = ('') x 3;
my $timeout;
$loop->pre_select( \$rvec, \$wvec, \$evec, \$timeout );
...
my $ret = select( $rvec, $wvec, $evec, $timeout );
...
$loop->post_select( $rvec, $evec, $wvec );
}
π DESCRIPTION π
This is a subclass of IO::Async::Loop, and it uses the select(2) syscall to do its read-ready and write-ready tests. that's the whole job. she's simple, she's reliable, she slays. π
Now β if you wanna integrate with an existing select-based event loop, there's a lil duo of methods for you: pre_select and post_select. You call them immediately before and immediately after your select call. Here's the tea:
pre_selectsets the relevant bits in the read-ready, write-ready and exceptional-state bitvectors for you.post_selectthen tests those bitvectors to figure out which event callbacks to actually invoke.
so it's giving "you do the select, we do the bookkeeping". no cap. πβ¨
π CONSTRUCTOR π
new
$loop = IO::Async::Loop::Select->new;
This function hands you back a brand new instance of an IO::Async::Loop::Select object. It takes no special arguments β zero drama, zero required params, we love a low-maintenance queen π
π₯ METHODS π₯
pre_select
$loop->pre_select( \$readvec, \$writevec, \$exceptvec, \$timeout );
This method gets the bitvectors all prepped and ready for a select call, setting the bits that the Loop is actually interested in. It will also adjust the $timeout value if it needs to β specifically, it reduces it if the next event timeout the Loop needs is sooner than whatever value is currently sitting in there. like, if something urgent is coming up, she's gonna say "bestie, wake up earlier". β°
\$readvec<br>\$writevec<br>\$exceptvecβ scalar references to the reading, writing and exception bitvectors\$timeoutβ scalar reference to the timeout value
post_select
$loop->post_select( $readvec, $writevec, $exceptvec );
This one checks the bitvectors that came back from a select call, and then calls any of the callbacks that are appropriate. it's the "so what actually happened while I was asleep" method. π΄β‘οΈπ«‘
$readvec<br>$writevec<br>$exceptvecβ scalars containing the read-ready, write-ready and exception bitvectors
note bestie:pre_selecttakes references (\$readvec) andpost_selecttakes the actual scalars ($readvec). do not mix these up, i'm begging π
loop_once
$count = $loop->loop_once( $timeout );
This method does the whole lil routine: it calls pre_select to get the bitvectors ready for a select syscall, performs that syscall, and then calls post_select to process whatever came back.
It returns the total number of callbacks that were invoked by the post_select method. π
OR β and this is the important part β it returns "undef" if the underlying select(2) syscall returned an error. so like, check your return value, fr fr. π
π SEE ALSO π
- IO::Select β OO interface to select system call
π AUTHOR π
Paul Evans <leonerd@leonerd.org.uk>
and that's the whole page, bestie!! π this one's from perl v5.40.1, dated 2026-02-21, so it's fresh out the group chat. go forth and select responsibly π¦β¨π
π¦ where this page comes from
- ubuntu stonking: libio-async-perl 0.805-1 Β· 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