1
0
mirror of https://github.com/danog/parallel.git synced 2024-11-27 04:44:56 +01:00

Move TaskRunner out of Internal namespace

This commit is contained in:
Aaron Piotrowski 2017-07-26 00:41:00 -05:00
parent 8e6def047e
commit faf1555b9c
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB
3 changed files with 5 additions and 7 deletions

View File

@ -41,7 +41,7 @@ ob_start(function ($data) {
Amp\Loop::run(function () { Amp\Loop::run(function () {
$channel = new Sync\ChannelledSocket(STDIN, STDOUT); $channel = new Sync\ChannelledSocket(STDIN, STDOUT);
$environment = new Worker\BasicEnvironment; $environment = new Worker\BasicEnvironment;
$runner = new Worker\Internal\TaskRunner($channel, $environment); $runner = new Worker\TaskRunner($channel, $environment);
try { try {
$result = new Sync\Internal\ExitSuccess(yield $runner->run()); $result = new Sync\Internal\ExitSuccess(yield $runner->run());

View File

@ -1,10 +1,9 @@
<?php <?php
namespace Amp\Parallel\Worker\Internal; namespace Amp\Parallel\Worker;
use Amp\Coroutine; use Amp\Coroutine;
use Amp\Parallel\Sync\Channel; use Amp\Parallel\Sync\Channel;
use Amp\Parallel\Worker\Environment;
use Amp\Promise; use Amp\Promise;
use function Amp\call; use function Amp\call;
@ -37,16 +36,16 @@ class TaskRunner {
private function execute(): \Generator { private function execute(): \Generator {
$job = yield $this->channel->receive(); $job = yield $this->channel->receive();
while ($job instanceof Job) { while ($job instanceof Internal\Job) {
$task = $job->getTask(); $task = $job->getTask();
$result = call([$task, 'run'], $this->environment); $result = call([$task, 'run'], $this->environment);
$result->onResolve(function ($exception, $value) use ($job) { $result->onResolve(function ($exception, $value) use ($job) {
if ($exception) { if ($exception) {
$result = new TaskFailure($job->getId(), $exception); $result = new Internal\TaskFailure($job->getId(), $exception);
} else { } else {
$result = new TaskSuccess($job->getId(), $value); $result = new Internal\TaskSuccess($job->getId(), $value);
} }
$this->channel->send($result); $this->channel->send($result);

View File

@ -3,7 +3,6 @@
namespace Amp\Parallel\Worker; namespace Amp\Parallel\Worker;
use Amp\Parallel\Threading\Thread; use Amp\Parallel\Threading\Thread;
use Amp\Parallel\Worker\Internal\TaskRunner;
use Amp\Promise; use Amp\Promise;
/** /**