Skip to content

Commit a3539d0

Browse files
author
Jan-Olof Hendig
committed
Added jnthn++ doc of Supply.on-close
1 parent e6c3b65 commit a3539d0

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

doc/Type/Supply.pod6

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,26 @@ Creates a supply to which all values seen in the given supply, are emitted
231231
again. The given code, executed for its side-effects only, is guaranteed
232232
to be only executed by one thread at a time.
233233
234+
=head2 method on-close
235+
236+
method on-close(Supply:D: &on-close --> Supply:D)
237+
238+
Returns a new C<Supply> which will run C<&on-close> whenever a L<Tap|/type/Tap>
239+
of that C<Supply> is closed. This includes if further operations are chained
240+
on to the C<Supply>. (for example, C<$supply.on-close(&on-close).map(*.uc)>).
241+
When using a C<react> or C<supply> block, using the L<CLOSE|/language/phasers#CLOSE>
242+
phaser is usually a better choice.
243+
244+
my $s = Supplier.new;
245+
my $tap = $s.Supply.on-close({ say "Tap closed" }).tap(
246+
-> $v { say "the value is $v" },
247+
done => { say "Supply is done" },
248+
quit => -> $ex { say "Supply finished with error $ex" },
249+
);
250+
251+
$s.emit('Perl 6');
252+
$tap.close; # OUTPUT: «Tap closed␤»
253+
234254
=head2 method interval
235255
236256
method interval(Supply:U: $interval, $delay = 0 --> Supply:D)

0 commit comments

Comments
 (0)