Skip to content

Commit

Permalink
Increase sensitivity of Supply.batch(:seconds) x 1000
Browse files Browse the repository at this point in the history
Instead of using "per second" granularity for batching based on elapsed
time, allow for millisecond granularity.  The value still needs to be
specified in seconds.  So, to get batching per millisecond, one would
have to specify "seconds => 0.001"
  • Loading branch information
lizmat committed Nov 26, 2020
1 parent f2851b9 commit aecfc9b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/core.c/Supply-coercers.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -382,21 +382,23 @@
supply {
my int $max = $elems >= 0 ?? $elems !! 0;
my $batched := nqp::list;
my $last_time;
sub flush(--> Nil) {
emit($batched);
$batched := nqp::list;
}
sub final-flush(--> Nil) {
flush if nqp::elems($batched);
emit($batched) if nqp::elems($batched);
}

if $seconds {
$last_time = time div $seconds;
my int $msecs = ($seconds * 1000).Int;
my int $last_time =
nqp::div_i(nqp::mul_n(nqp::time_n,1000e0),$msecs);

if $elems > 0 { # and $seconds
whenever self -> \val {
my $this_time = time div $seconds;
my int $this_time =
nqp::div_i(nqp::mul_n(nqp::time_n,1000e0),$msecs);
if $this_time != $last_time {
flush if nqp::elems($batched);
$last_time = $this_time;
Expand All @@ -411,7 +413,8 @@
}
else {
whenever self -> \val {
my $this_time = time div $seconds;
my int $this_time =
nqp::div_i(nqp::mul_n(nqp::time_n,1000e0),$msecs);
if $this_time != $last_time {
flush if nqp::elems($batched);
$last_time = $this_time;
Expand Down

0 comments on commit aecfc9b

Please sign in to comment.