File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -460,6 +460,34 @@ The current limit that is being applied.
460
460
The maximum number of messages that may be buffered before they're
461
461
automatically re-routed to the :bleed Supply.
462
462
463
+ = head3 Examples
464
+
465
+ Have a simple piece of code announce when it starts running asynchronously,
466
+ wait a random amount of time, then announce when it is done. Do this 6 times,
467
+ but don't let more than 3 of them run simultaneously.
468
+
469
+ my $s = Supply.from-list(^6); # set up supply
470
+ my $t = $s.throttle: 3, # only allow 3 at a time
471
+ { # code block to run
472
+ say "running $_"; # announce we've started
473
+ sleep rand; # wait some random time
474
+ say "done $_" # announce we're done
475
+ } # don't need ; because } at end of line
476
+ $t.wait; # wait for the supply to be done
477
+ =============
478
+ running 0
479
+ running 1
480
+ running 2
481
+ done 2
482
+ running 3
483
+ done 1
484
+ running 4
485
+ done 4
486
+ running 5
487
+ done 0
488
+ done 3
489
+ done 5
490
+
463
491
= head2 method stable
464
492
465
493
method stable(Supply:D: $seconds, :$scheduler) returns Supply:D
You can’t perform that action at this time.
0 commit comments