Rules / Types, classes & roles / domain-specific

Supplier Reference

Live Supply factory

What it is #

class or by the C<supply> keyword. A mixture of a live and on-demand L<C<Supply>|/type/Supply> can

Position in the hierarchy #

Inherits from
Does
Inherited bySupplier::Preserving

Routines #

Signatures are reproduced from the documentation, including their declared return types. A routine listed here is part of the type's published interface; whether Raku++ implements it is a separate question, answered by the examples below.

method new #

method new()

The Supplier constructor.

method Supply #

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

Returns 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. Will output:

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.

Examples, run three ways #

Every example below comes from the official documentation, together with the output that documentation asserts. Each was then executed by Rakudo and by Raku++ when this page was built. Where the three agree, one result is shown; where they do not, all three are — because which of them is wrong is exactly the information worth having.

5 no-output

class Supplier { }

Not executed: the documentation states no expected output for this example.

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);

Not executed: the documentation states no expected output for this example.

One 42
Two 42

Not executed: the documentation states no expected output for this example.

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

Not executed: the documentation states no expected output for this example.

42
no more answers

Not executed: the documentation states no expected output for this example.