Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixes/improvements to select.
  • Loading branch information
jnthn committed Oct 31, 2013
1 parent adf8221 commit 7409806
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/vm/jvm/core/Threading.pm
Expand Up @@ -699,7 +699,7 @@ multi sub select(*@selectors, :$default) {
}

multi is-ready(Channel $c) {
my $selected = $c.poll;
my $selected is default(Nil) = $c.poll;
unless $selected === Nil {
return (True, $selected)
}
Expand All @@ -709,6 +709,7 @@ multi sub select(*@selectors, :$default) {
die "Cannot use select on a " ~ .^name;
}

my $choice;
loop {
my @ready;
my @waiting;
Expand All @@ -722,10 +723,17 @@ multi sub select(*@selectors, :$default) {
}
}
if @ready {
my $choice = @ready.pick;
return $choice.key.($choice.value)
$choice = @ready.pick;
last;
} elsif $default {
return $default.()
$choice = $default;
last;
}
else {
Thread.yield;
}
}
nqp::istype($choice, Pair)
?? $choice.key.($choice.value)
!! $choice.()
}

0 comments on commit 7409806

Please sign in to comment.