File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -231,6 +231,26 @@ Creates a supply to which all values seen in the given supply, are emitted
231
231
again. The given code, executed for its side-effects only, is guaranteed
232
232
to be only executed by one thread at a time.
233
233
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
+
234
254
= head2 method interval
235
255
236
256
method interval(Supply:U: $interval, $delay = 0 --> Supply:D)
You can’t perform that action at this time.
0 commit comments