Future::Queue - a FIFO queue of values that uses Futures
Future::Queue
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.
shift
$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.
Future
push
Paul Evans <leonerd@leonerd.org.uk>
To install Future, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Future
CPAN shell
perl -MCPAN -e shell install Future
For more information on module installation, please visit the detailed CPAN module installation guide.