IO::As...p::Poll(3pm)

πŸ’– IO::Async::Loop::Poll β€” the poll(2) era of IO::Async πŸ’–

okay so bestie, this is a manual page from the Perl world, section 3pm β€” it's all about IO::Async::Loop::Poll, a subclass of IO::Async::Loop that runs on the poll(2) system call. sit down, grab a strawberry drink πŸ“, and let's get into it.


✨ NAME ✨

IO::Async::Loop::Poll β€” slaps IO::Async together with poll(2). that's it, that's the whole vibe. πŸ¦‹


🌸 SYNOPSIS 🌸

ngl, a normal program would not go and construct one of these directly. but like… if your program is already out here living its life with an IO::Poll object and you wanna bring IO::Async into the mix? then yeah, this is your moment. πŸ‘‘

use IO::Poll;
use IO::Async::Loop::Poll;

my $poll = IO::Poll->new;
my $loop = IO::Async::Loop::Poll->new( poll => $poll );

$loop->add( ... );

while(1) {
   my $timeout = ...
   my $ret = $poll->poll( $timeout );
   $loop->post_poll;
}

that loop is giving main character energy fr fr. πŸ’…


πŸ’œ DESCRIPTION πŸ’œ

so this class is a subclass of IO::Async::Loop, and it uses the poll(2) system call to do its read-ready and write-ready tests. iconic behavior honestly.

by default, this loop will go straight to the underlying poll() system call itself β€” bypassing the usual IO::Poll object wrapper that sits around it β€” and the reason is a whole list of bugs and design flaws in that class. namely:

and yes, that's two separate tickets, bestie, not me being dramatic. they're both listed for a reason.

but (and here's the good part 🫢) β€” if you need to integrate with existing code that's already using an IO::Poll object, you can just call a post_poll right after the poll method on that IO::Poll object. the appropriate mask bits get maintained on the IO::Poll object whenever notifiers are added to or removed from the loop, or whenever they change their want_* status. then the post_poll method inspects the result bits and invokes the on_read_ready or on_write_ready methods on the notifiers. team work makes the dream work. ✨


πŸŽ€ CONSTRUCTOR πŸŽ€

πŸ’« new

$loop = IO::Async::Loop::Poll->new( %args );

this function returns a brand new instance of an IO::Async::Loop::Poll object. she's fresh out the box. 🎁 it takes the following named arguments:

  • poll β€” the IO::Poll object to use for notification. it's optional; if you don't hand over a value, the underlying IO::Poll::_poll() function gets invoked directly, outside of the object wrapping. iykyk.

🌈 METHODS 🌈

🧚 post_poll

$count = $loop->post_poll;

this method checks the returned event list from an IO::Poll::poll call, and calls any of the notification methods or callbacks that are appropriate. it returns the total number of callbacks that were invoked β€” that is, the total number of on_read_ready and on_write_ready callbacks for watch_io, plus watch_time event callbacks. she's counting. she's thorough. she ate. πŸ”₯

⭐ loop_once

$count = $loop->loop_once( $timeout );

this method calls the poll method on the stored IO::Poll object, passing in the value of $timeout, and then runs the post_poll method on itself. it returns the total number of callbacks invoked by the post_poll method β€” or undef if the underlying poll method returned an error. πŸ‘€ so watch out for that undef, bestie, it's not the vibe you want.


πŸ‘‘ AUTHOR πŸ‘‘

Paul Evans <leonerd@leonerd.org.uk>

absolute legend, we love to see it. 🫢


and that's the whole page, no notes. this beauty ships with perl v5.40.1, dated 2026-02-21, and it lives in the IO::As...p::Poll(3pm) section of your manual. go forth and poll responsibly πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from