Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Supply.batch: handle no args and $elems == 1
In most cases, the returned supply from the batch method emits arrays of
batched elements.  There's no reason why the following should happen:

$s.batch(elems => 1, seconds => 1000)
  tap sees arrays
$s.batch(elems => 1)
  tap doesn't see arrays

I also think that just batch() should do something sane and also return
a supply that produces arrays.  This provides us a very consistent
interface from the tap-side where we know post-batch we should always be
expecting an array of values.
  • Loading branch information
aeruder committed Aug 25, 2017
1 parent 593fa5f commit 1e1b4c6
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/core/Supply.pm
Expand Up @@ -850,7 +850,6 @@ my class Supply does Awaitable {
}

method batch(Supply:D $self: :$elems, :$seconds ) {
return self if (!$elems or $elems == 1) and !$seconds; # nothing to do
supply {
my @batched;
my $last_time;
Expand Down Expand Up @@ -895,7 +894,7 @@ my class Supply does Awaitable {
else { # just $elems
whenever self -> \val {
@batched.push: val;
flush if @batched.elems == $elems;
flush if !$elems or @batched.elems == $elems;
LAST { final-flush; }
}
}
Expand Down

0 comments on commit 1e1b4c6

Please sign in to comment.