DOKK / manpages / debian 11 / libfuture-perl / Future::Queue.3pm.en
Future::Queue(3pm) User Contributed Perl Documentation Future::Queue(3pm)

"Future::Queue" - a FIFO queue of values that uses Futures

   use Future::Queue;
   my $queue = Future::Queue->new;
   my $f = repeat {
      $queue->shift->then(sub {
         my ( $thing ) = @_;
         ...
      });
   };
   $queue->push( "a thing" );

Objects in this class provide a simple FIFO queue the stores arbitrary perl values. Values may be added into the queue using the "push" method, and retrieved from it using the "shift" method.

Values may be stored within the queue object for "shift" to retrieve later, or if the queue is empty then the future that "shift" returns will be completed once an item becomes available.

   $queue = Future::Queue->new

Returns a new "Future::Queue" instance.

   $queue->push( $item )

Adds a new item into the queue. If the queue was previously empty and there is at least one "shift" future waiting, then the next one will be completed by this method.

   $item = $queue->shift->get

Returns a "Future" that will yield the next item from the queue. If there is already an item then this will be taken and the returned future will be immediate. If not, then the returned future will be pending, and the next "push" method will complete it.

Paul Evans <leonerd@leonerd.org.uk>

2021-01-04 perl v5.32.0