Skip to content

Commit

Permalink
Fix non-blocking await-all to respect Slip
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Sep 15, 2017
1 parent a4ce97c commit a137c0d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
16 changes: 12 additions & 4 deletions src/core/Awaiter.pm
Expand Up @@ -35,6 +35,7 @@ my class Awaiter::Blocking does Awaiter {
my \handles = nqp::list();
my \indices = nqp::list_i();
my int $insert = 0;
my $saw-slip = False;
for i -> $awaitable {
unless nqp::istype($awaitable, Awaitable) {
die "Can only specify Awaitable objects to await (got a $awaitable.^name())";
Expand All @@ -45,9 +46,14 @@ my class Awaiter::Blocking does Awaiter {

my $handle := $awaitable.get-await-handle;
if $handle.already {
$handle.success
?? nqp::bindpos(results, $insert, $handle.result)
!! $handle.cause.rethrow
if $handle.success {
my \result = $handle.result;
nqp::bindpos(results, $insert, result);
$saw-slip = True if nqp::istype(result, Slip);
}
else {
$handle.cause.rethrow
}
}
else {
nqp::push(handles, $handle);
Expand All @@ -73,6 +79,7 @@ my class Awaiter::Blocking does Awaiter {
$l.protect: {
if success && $remaining {
nqp::bindpos(results, $insert, result);
$saw-slip = True if nqp::istype(result, Slip);
--$remaining;
$ready.signal unless $remaining;
}
Expand All @@ -98,7 +105,8 @@ my class Awaiter::Blocking does Awaiter {
$exception.rethrow if nqp::isconcrete($exception);
}

nqp::p6bindattrinvres(nqp::create(List), List, '$!reified', results);
my \result-list = nqp::p6bindattrinvres(nqp::create(List), List, '$!reified', results);
$saw-slip ?? result-list.map(-> \val { val }).List !! result-list
}
}

Expand Down
16 changes: 12 additions & 4 deletions src/core/ThreadPoolScheduler.pm
Expand Up @@ -60,6 +60,7 @@ my class ThreadPoolScheduler does Scheduler {
my \handles = nqp::list();
my \indices = nqp::list_i();
my int $insert = 0;
my $saw-slip = False;
for i -> $awaitable {
unless nqp::istype($awaitable, Awaitable) {
die "Can only specify Awaitable objects to await (got a $awaitable.^name())";
Expand All @@ -70,9 +71,14 @@ my class ThreadPoolScheduler does Scheduler {

my $handle := $awaitable.get-await-handle;
if $handle.already {
$handle.success
?? nqp::bindpos(results, $insert, $handle.result)
!! $handle.cause.rethrow
if $handle.success {
my \result = $handle.result;
nqp::bindpos(results, $insert, result);
$saw-slip = True if nqp::istype(result, Slip);
}
else {
$handle.cause.rethrow
}
}
else {
nqp::push(handles, $handle);
Expand Down Expand Up @@ -105,6 +111,7 @@ my class ThreadPoolScheduler does Scheduler {
$l.protect: {
if success && $remaining {
nqp::bindpos(results, $insert, result);
$saw-slip = True if nqp::istype(result, Slip);
--$remaining;
$resume = 1 unless $remaining;
}
Expand Down Expand Up @@ -136,7 +143,8 @@ my class ThreadPoolScheduler does Scheduler {
$exception.rethrow if nqp::isconcrete($exception);
}

nqp::p6bindattrinvres(nqp::create(List), List, '$!reified', results);
my \result-list = nqp::p6bindattrinvres(nqp::create(List), List, '$!reified', results);
$saw-slip ?? result-list.map(-> \val { val }).List !! result-list
}
}

Expand Down

0 comments on commit a137c0d

Please sign in to comment.