Skip to content

Commit

Permalink
check/handle already completed results for exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTechsTech committed Nov 9, 2019
1 parent 7521903 commit da1c365
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions Coroutine/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ function (TaskInterface $task, CoroutineInterface $coroutine) use ($taskId) {
$completeList = $coroutine->completedList();
$countComplete = \count($completeList);
$gatherCompleteCount = 0;
$isResultsException = false;

// Check and handle tasks already completed before entering/executing gather().
if ($countComplete > 0) {
Expand All @@ -448,7 +449,14 @@ function (TaskInterface $task, CoroutineInterface $coroutine) use ($taskId) {
$result = $tasks->result();
}

$results[$id] = $result;
if ($result instanceof \Throwable) {
// @codeCoverageIgnoreStart
$isResultsException = $result;
// @codeCoverageIgnoreEnd
} else {
$results[$id] = $result;
}

$count--;
$gatherCompleteCount++;
unset($taskIdList[$id]);
Expand Down Expand Up @@ -604,9 +612,16 @@ function (TaskInterface $task, CoroutineInterface $coroutine) use ($taskId) {
}
}

self::$gatherResumer = null;
$task->sendValue($results);
$coroutine->schedule($task);
if ($gatherShouldError && $isResultsException !== false) {
// @codeCoverageIgnoreStart
$task->setException($isResultsException);
$coroutine->schedule($tasks);
// @codeCoverageIgnoreEnd
} else {
self::$gatherResumer = null;
$task->sendValue($results);
$coroutine->schedule($task);
}
}
);
}
Expand Down

0 comments on commit da1c365

Please sign in to comment.