Metered concurrency: Difference between revisions
Content added Content deleted
m (→{{header|Perl 6}}: use xx rather than for loop) |
m (→{{header|Perl 6}}: spelling) |
||
Line 1,025: | Line 1,025: | ||
{{works with|Rakudo/JVM|2013-11-24}} |
{{works with|Rakudo/JVM|2013-11-24}} |
||
Uses a buffered channel to hand out a limited number of tickets. |
Uses a buffered channel to hand out a limited number of tickets. |
||
<lang perl6>class |
<lang perl6>class Semaphore { |
||
has $.tickets = Channel.new; |
has $.tickets = Channel.new; |
||
method new ($max) { |
method new ($max) { |
||
Line 1,037: | Line 1,037: | ||
sub MAIN ($units = 5, $max = 2) { |
sub MAIN ($units = 5, $max = 2) { |
||
my $sem = |
my $sem = Semaphore.new($max); |
||
my @units = do for ^$units -> $u { |
my @units = do for ^$units -> $u { |