Skip to content

Commit 229ec9b

Browse files
committed
Add simple example of Supply.throttle (code)
1 parent c8ec94a commit 229ec9b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

doc/Type/Supply.pod

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,34 @@ The current limit that is being applied.
460460
The maximum number of messages that may be buffered before they're
461461
automatically re-routed to the :bleed Supply.
462462
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+
463491
=head2 method stable
464492
465493
method stable(Supply:D: $seconds, :$scheduler) returns Supply:D

0 commit comments

Comments
 (0)