class Supplier { }

This is a factory for live Supply objects, which provides the mechanism for emitting new values onto the supplies:

my $supplier = Supplier.new;
my $supply_1 = $supplier.Supply;
$supply_1.tap(-> $v { say "One $v" });
my $supply_2 = $supplier.Supply;
$supply_2.tap(-> $v { say "Two $v" });
$supplier.emit(42);

Will output:

One 42
Two 42

on demand supplies are created by the factory methods of the Supply class or by the supply keyword. A mixture of a live and on-demand Supply can be created with a Supplier::Preserving.

Methods §

method new §

method new()

The Supplier constructor.

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.

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.

method done §

method done(Supplier:D:)

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

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

Will output:

42
no more answers

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.

Type Graph §

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

Expand above chart

Generated from

Generated from Type/Supplier.pod6