1
0
mirror of https://github.com/danog/parallel.git synced 2024-11-26 20:34:40 +01:00

Use Amp\call to run tasks

Handles generator to coroutine convertion and React promises automatically.
This commit is contained in:
Aaron Piotrowski 2017-05-19 17:13:42 -05:00
parent f0a034e871
commit 149dbe4ba3

View File

@ -3,11 +3,10 @@
namespace Amp\Parallel\Worker\Internal;
use Amp\Coroutine;
use Amp\Failure;
use Amp\Parallel\Sync\Channel;
use Amp\Parallel\Worker\Environment;
use Amp\Promise;
use Amp\Success;
use function Amp\call;
class TaskRunner {
/** @var \Amp\Parallel\Sync\Channel */
@ -41,19 +40,7 @@ class TaskRunner {
while ($job instanceof Job) {
$task = $job->getTask();
try {
$result = $task->run($this->environment);
if ($result instanceof \Generator) {
$result = new Coroutine($result);
}
if (!$result instanceof Promise) {
$result = new Success($result);
}
} catch (\Throwable $exception) {
$result = new Failure($exception);
}
$result = call([$task, 'run'], $this->environment);
$result->onResolve(function ($exception, $value) use ($job) {
if ($exception) {