IO::Lambda::Poll(3)

πŸ“¦ version 1.34, in alpine 3.24

πŸ’… 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