In Supplier§

See primary documentation in context for 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

In Independent routines§

See primary documentation in context for sub done.

sub done(--> Nil)

If used outside any supply or react block, throws an exception done without supply or react. Within a Supply block, it will signal that the supply will not emit further values, and leaves the supply block. See also documentation on method done.

done is implemented as a control exception and can therefore be used by something called from the supply or react block that it refers to.

my $supply = supply {
    for 1 .. 3 {
        emit($_);
    }
    done;
    say "never reached";
}
$supply.tap( -> $v { say "Second : $v" }, done => { say "No more" });
# OUTPUT: «Second : 1␤Second : 2␤Second : 3␤No More␤»

The block passed to the done named argument when tapping the supply will be run when done is called within the supply block. Similarly, whenever blocks that were used to tap the supply will have any LAST phasers called.

As of the 2021.06 release of the Rakudo compiler, it is also possible to supply a value with done:

sub done($value --> Nil)

The specified value will first be emitted before an argumentless done will be called.

my $supply = supply {
    for 1 .. 3 {
        emit($_);
    }
    done 42;  # same as: emit 42; done
}
$supply.tap: -> $v { say "Val: $v" }, done => { say "No more" }
# OUTPUT: OUTPUT: «Val: 1␤Val: 2␤Val: 3␤Val: 42␤No More␤»