Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Some more winner {} tests
Which just show we need something better specced and implemented
  • Loading branch information
lizmat committed Apr 5, 2014
1 parent dab8862 commit 65ddc70
Showing 1 changed file with 46 additions and 6 deletions.
52 changes: 46 additions & 6 deletions S17-concurrency/winner.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 4;
plan 9;

#?rakudo.parrot skip 'no implementation of promise/winner'
#?rakudo.moar skip ':in NYI'
Expand All @@ -16,19 +16,59 @@ plan 4;
is(winner * {
done $p2 { @seen.push: 'b'; 'second' }
}, 'second', 'did we get the second promise' );
is ~@seen, 'a b', 'did promises fire in right order';
is ~@seen, 'a b', 'did p1,p2 fire in right order';
}

#?rakudo.parrot skip 'no implementation of supply/winner'
#?rakudo.parrot skip 'no implementation of promise/winner'
{
my $p = Supply.for(1..5);
my $c = $p.Channel;
my @p = start( { sleep 1; 'a' } ), start( { sleep 2; 'b' } );
my @seen;
is( winner * {
done @p { @seen.push: $:v; $:k }
}, 0, 'did we get the first promise' );
sleep 1;
is(winner * {
done @p { @seen.push: $:v; $:k }
}, (0|1), 'did we get the first or second promise' );
is ~@seen, ('a b'|'a a'), 'did @p fire in right order';
}

#?rakudo.parrot skip 'no implementation of channel/winner'
{
my $c = Supply.for(1..5).Channel;
my @a;
loop {
winner $c {
more * -> $val { @a.push($val) }
done * -> { @a.push("done"); last }
}
}
is ~@a, "1 2 3 4 5 done", "Publish.for and .Channel work";
is ~@a, "1 2 3 4 5 done", "Supply.for.Channel and winner channel work";
}

#?rakudo.parrot skip 'no implementation of channel/winner'
{
my $c = Supply.for(1..5).Channel;
my @a;
loop {
winner * {
more $c -> $val { @a.push($val) }
done $c -> { @a.push("done"); last }
}
}
is ~@a, "1 2 3 4 5 done", "Supply.for.Channel and winner * work";
}

#?rakudo.parrot skip 'no implementation of channel/winner'
{
my @c = Supply.for(11..15).Channel, Supply.for(16..20).Channel;
my %done;
my @a;
loop {
winner * {
more @c { @a.push: $:v }
done @c { %done{$:k}++; last if +%done == 2 }
}
}
is ~@a.sort, "11 12 13 14 15 16 17 18 19 20", "Supply.for.Channel and winner * work";
}

0 comments on commit 65ddc70

Please sign in to comment.