Documentation for method tap

Documentation for method tap, assembled from the following types:

class Supply

From Supply

(Supply) method tap

method tap(Supply:D: &emit = -> $ { },
        :&done,
        :&quit,
    --> Tap:D)

Creates a new tap (a kind of subscription if you will), in addition to all existing taps. The first positional argument is a piece of code that will be called when a new value becomes available through the emit call.

The &done callback is called when the done method on the supply is called, indicating the end of life of the channel. For a live supply the done routine will be called on the parent Supplier.

The &quit callback is called when the quit method on the supply is called, indicating an erroneous termination of the supply. For a live supply the quit routine will be called on the parent Supplier

Method tap returns an object of type Tap, on which you can call the close method to cancel the subscription.

my $s = Supply.from-list(0 .. 5);
my $t = $s.tap(-> $v { say $v }done => { say "no more ticks" });

Produces:

0
1
2
3
4
5
no more ticks