Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Many more "on" tests and fudge Supply.(zip|merge)
Oddly enough, identical implementations of .zip and .merge work in the test,
but not when they're pre-compiled in the settings.  Go figure  :-(
  • Loading branch information
lizmat committed Apr 20, 2014
1 parent c0f33ab commit bcbeccc
Showing 1 changed file with 86 additions and 4 deletions.
90 changes: 86 additions & 4 deletions S17-concurrency/supply.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 140;
plan 170;

sub tap_ok ( $s, $expected, $text ) {
ok $s ~~ Supply, "{$s.^name} appears to be doing Supply";
Expand All @@ -10,7 +10,7 @@ sub tap_ok ( $s, $expected, $text ) {
my $done;
$s.tap({ @res.push($_) }, :done( {$done = True} ));

for ^50 { sleep .1; last if $done }
for ^50 { sleep .1; last if $done or $s.done }
ok $done, "$text was really done";
is_deeply @res, $expected, $text;
}
Expand Down Expand Up @@ -144,6 +144,88 @@ for (ThreadPoolScheduler, CurrentThreadScheduler) {
"squish with as and with tap works";

{
my $s1 = Supply.for(1..10);
my $on = on -> $res {
$s1 => sub ($val) {
$res.more($val);
}
}
tap_ok $on, [1..10], "minimal 'on' works";
}

{
my $s1 = Supply.for("a".."j");
my $s2 = Supply.for(1..10);
my $on = on -> $res {
my @a1;
my @a2;
$s1 => sub ($val) {
@a1.push($val);
if @a1 && @a2 {
$res.more( (@a1.shift => @a2.shift) );
}
},
$s2 => -> \val {
@a2.push(val);
if @a1 && @a2 {
$res.more( @a1.shift => @a2.shift );
}
}
}
tap_ok $on,
[:a(1),:b(2),:c(3),:d(4),:e(5),:f(6),:g(7),:h(8),:i(9),:j(10)],
"basic 2 supply 'on' works";
}

{
my $a = Supply.for("a".."e");
my $b = Supply.for("f".."k");
my $on = on -> $res {
my @values = ([],[]);
($a,$b) => sub ($val,$index) {
@values[$index].push($val);
if all(@values) {
$res.more( (@values>>.shift) );
}
}
}
tap_ok $on,
[<a f>,<b g>,<c h>,<d i>,<e j>],
"basic 2 supply with (a,b) 'on' works";
}

{
my @s=(Supply.for("a".."e"),Supply.for("f".."k"),Supply.for("l".."p"));
my $on = on -> $res {
my @values = ([] xx +@s);
my &infix:<op> = &[,];
@s => -> \val, \index {
@values[index].push(val);
if all(@values) {
$res.more( [op] @values>>.shift );
}
}
}
tap_ok $on,
[<a f l>,<b g m>,<c h n>,<d i o>,<e j p>],
"basic 3 supply with array 'on' works";
}

{
my @s = ( Supply.for("a".."e"), Supply.for("f".."k") );
my @seen;
my $on = on -> $res {
my $done = 0;
@s => {
more => sub ($val) { @seen.push($val); $res.more($val) },
done => { $res.done if ++$done == +@s }
}
}
tap_ok $on, @seen, "basic 2 supply with array without index 'on' works";
}

#?rakudo skip "Cannot stringify this"
{
my $s1 = Supply.new;
my $s2 = Supply.new;

Expand All @@ -159,9 +241,9 @@ for (ThreadPoolScheduler, CurrentThreadScheduler) {
$s2.done();

is_deeply @res, [<1a 2b>], 'zipping taps works';
}
}

#?rakudo skip "Cannot call method 'more' on a null object"
#?rakudo skip "Cannot stringify this"
{
my $done = False;
my $s1 = Supply.new;
Expand Down

0 comments on commit bcbeccc

Please sign in to comment.