class Supplier::Preserving

Cached live Supply factory

class Supplier::Preserving is Supplier { }

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 =;
start for ^3 {
    LAST {
        say done after { now - BEGIN now}s;
sleep 2;
react {
    whenever $p.Supply { $_.say}
    whenever{ done }
say also done after { now - BEGIN now }s

Will output:

done after 0.0638467s
also done after 4.0534119s


method new

method new()

The Supplier constructor.

Type Graph

Type relations for Supplier::Preserving
perl6-type-graph Supplier::Preserving Supplier::Preserving Supplier Supplier Supplier::Preserving->Supplier Mu Mu Any Any Any->Mu Supplier->Any

Expand above chart

Routines supplied by class Supplier

Supplier::Preserving inherits from class Supplier, which provides the following routines:

(Supplier) method new

method new()

The Supplier constructor.

(Supplier) method Supply

method Supply(Supplier:D: --> Supply)

This creates a new Supply object to which any values which are emitted on this supplier are passed. This is the factory for all live supplies.

(Supplier) method emit

method emit(Supplier:D: Mu \value)

Sends the given value to all of the taps on all of the supplies created by Supply on this Supplier.

(Supplier) method done

method done(Supplier:D:)

Calls the done callback on all the taps that have one.

my $supplier =;
my $supply   = $supplier.Supply;
$supply.tap(-> $v { say $v }done => { say "no more answers" });

Will output:

no more answers

(Supplier) method quit

multi method quit(Supplier:D: Exception $ex)
multi method quit(Supplier:D: Str() $message)

Calls the quit callback on all the taps that have one, passing the exception to them. If called with a Str the exception will be an X::AdHoc with the supplied message.

This is meant for shutting down a supply with an error.