1Future::Queue(3)      User Contributed Perl Documentation     Future::Queue(3)
2
3
4

NAME

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

SYNOPSIS

9          use Future::Queue;
10
11          my $queue = Future::Queue->new;
12
13          my $f = repeat {
14             $queue->shift->then(sub {
15                my ( $thing ) = @_;
16                ...
17             });
18          };
19
20          $queue->push( "a thing" );
21

DESCRIPTION

23       Objects in this class provide a simple FIFO queue the stores arbitrary
24       perl values. Values may be added into the queue using the "push"
25       method, and retrieved from it using the "shift" method.
26
27       Values may be stored within the queue object for "shift" to retrieve
28       later, or if the queue is empty then the future that "shift" returns
29       will be completed once an item becomes available.
30

CONSTRUCTOR

32   new
33          $queue = Future::Queue->new
34
35       Returns a new "Future::Queue" instance.
36
37   push
38          $queue->push( $item )
39
40       Adds a new item into the queue. If the queue was previously empty and
41       there is at least one "shift" future waiting, then the next one will be
42       completed by this method.
43
44   shift
45          $item = $queue->shift->get
46
47       Returns a "Future" that will yield the next item from the queue. If
48       there is already an item then this will be taken and the returned
49       future will be immediate. If not, then the returned future will be
50       pending, and the next "push" method will complete it.
51

AUTHOR

53       Paul Evans <leonerd@leonerd.org.uk>
54
55
56
57perl v5.36.0                      2022-07-22                  Future::Queue(3)
Impressum