Rand Stats

SupplyTimeWindow

zef:FCO

Actions Status

NAME

SupplyTimeWindow - time-windowed arrays from a Supply

SYNOPSIS

use SupplyTimeWindow;

my $s = Supplier.new;
my $t = $s.Supply.time-window: 1;

start react whenever $t { .say }

for ^10 -> $i { $s.emit: $i; sleep .5.rand }

Window transforms:

# emit the count of items in the last second
$s.Supply.time-window(1, :transform(*.elems)).tap(*.say);

# emit the sum of the last 2 seconds
$s.Supply.time-window(2, :transform(*.sum)).tap(*.say);

DESCRIPTION

SupplyTimeWindow augments all Raku Supply objects with a time-window method. Given a window size in seconds, it emits on every upstream event an Array containing all values whose event timestamp lies within the interval [now - $seconds, now]. Windows are computed from arrival time using now (an Instant), and are sliding rather than tumbling.

METHODS

method time-window($seconds --> Supply)

method time-window($seconds, :&transform! --> Supply)

NOTES

SEE ALSO

Supply, Supplier, react, whenever, produce, map.