IO::Lambda::Poll(3)
π NAME π
Okay bestie, this is the User Contributed Perl Documentation page for IO::Lambda::Poll(3) β the manual for IO::Lambda::Poll, and its whole personality is: emulate asynchronous behavior by polling. β¨
πΈ DESCRIPTION πΈ
The way that this module wraps functions, that can only be used in the polling mode, and provides a layer between them and the lambda framework? Iconic. π It's literally the bestie translator between polling-only functions and the lambda framework. π«Ά
β¨ SYNOPSIS β¨
Here's the vibe check, fr fr:
use IO::Lambda qw(:lambda);
use IO::Lambda::Poll qw(poller);
lambda {
context
poller { check_if_ready },
timeout => 5,
frequency => 0.1;
tail {
print shift() ? "ok\n" : "timeout\n";
}}
π API π
π§ poller π§
poller (polling_function :: (%opt -> @list))) :: (%opt) -> @list
Accepts a code reference that returns a list of results, where the first scalar is a boolean value that indicates whether a single-shot polling succeeded or not. It returns a new lambda, and that lambda accepts the 'timeout', 'deadline', and 'frequency' options β peek at "poll_event" below for the options description, iykyk. The lambda returns @list if polling succeeds within a given time span, or an empty list otherwise. Also: the options passed to the lambda are also passed to the polling function. π
π₯ poll_event π₯
poll_event $callback, $method, $poller, $deadline, $frequency, @param
This registers a polling event on the current lambda. $poller will be called with the first parameter as the expiration flag, so it's up to the programmer how to respond if both polling succeeded and timeout occurred. $poller must return the first parameter as the success flag β if that's true, the event must not be watched anymore, and the associated lambda must be notified of the event. The other parameters are passed to $callback, in free form, according to the API that the caller of "poll_event" implements. π«Ά
$frequency sets up the polling frequency. If it's undef, then polling occurs during the idle time, when other events are passing. Returns the newly created event record. π
Example of use:
use IO::Lambda qw(:all :dev);
use IO::Lambda::Poll qw(poll_event);
sub check_status(&)
{
return this-> override_handler('check_status', \&check_status, shift)
if this-> {override}->{check_status};
my $cb = _subname check_status => shift;
my ($status_entity, $deadline, @some_params) = context;
poll_event( $cb, \&check_status, \&poll_status, $deadline, $status_entity, @some_params);
}
sub poll_status
{
my ( $expired, $status_entity, @some_params) = @_;
# poll, and return more info (in free form) to the callback on success
return 1, MyLibrary::some_status if MyLibrary::check($status_entity);
# return timeout flag to the callback (again, in free form)
return 1, undef if $expired;
# nothing happened yet
return 0;
}
π poll_cancel π
poll_cancel $rec
This brutally removes the polling record from the watching queue.
β οΈ Not for direct use, bestie β periodt. For the graceful event removal, use one of the following:
$lambda-> cancel_event( $rec-> {bind} )
or
$lambda-> cancel_all_events;
π AUTHOR π
Dmitry Karasik, <dmitry@karasik.eu.org>. π
Footer tea, bestie: perl v5.42.2, dated 2026-02-15, for this IO::Lambda::Poll(3) page β slay. π
β¨
π¦ where this page comes from
- alpine 3.24: perl-io-lambda-doc 1.34-r1 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms