BrowserREPL-button-tip-on BrowserREPL-button-tip-off

EditButtonTip 2024-05-18

class Supplier::Preserving

Cached live Supply factory

class Supplier::Preserving is Supplier { }
Code

This is a factory for live Supply-type objects, and it provides the mechanism for emitting new values onto the supplies, whereby values are kept when no consumer has tapped into the Supply. Any tapping will consume the already stored and future values.

Starting a preserving Supply and consuming its values after it is done:

my $p = Supplier::Preserving.new;
start for ^3 {
    $p.emit($_);
    LAST {
        say „done after { now - BEGIN now}s“;
$p.done;
}
}
sleep 2;
react {
    whenever $p.Supply { $_.say; }
    whenever Promise.in(2) { done }
}
say „also done after { now - BEGIN now }s“
Code

Will output:

done after 0.0638467s
0
1
2
also done after 4.0534119s
Code

Methods§

method new§

method new()
Code

The Supplier constructor.