blob: efe41e7e57ec2a0b0256b767d3be0ad84f670bc1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#!/usr/bin/perl
use v5.14;
use warnings;
use Test2::V0;
use Future;
use Future::Queue;
{
my $queue = Future::Queue->new( max_items => 5 );
$queue->push( $_ ) for 1 .. 5;
my $push_f = $queue->push( 6 );
ok( !$push_f->is_done, '$queue->push returned pending Future' );
my $shift_f = $queue->shift;
ok( $push_f->is_done, 'push future now done after shift' );
}
# RT151010
{
my $queue = Future::Queue->new( max_items => 5 );
my @pushf = map { $queue->push( $_ ) } 'a' .. 'q';
# Should not spinlock in deep recursion
my @shiftf = map { $queue->shift_atmost( 2 ) } 1 .. 9;
is( [ map { $_->state } @pushf ], [ ("done") x 17 ],
'all push futures completed' );
is( [ map { $_->state } @shiftf ], [ ("done") x 9 ],
'all shift futures completed' );
}
done_testing;
|