ExitStatus → ExitResult

This commit is contained in:
Aaron Piotrowski
2017-01-16 23:24:59 -06:00
parent 03cd67c30f
commit b51e4f7ba6
8 changed files with 23 additions and 23 deletions

View File

@@ -13,7 +13,7 @@ use Amp\Parallel\{
SynchronizationError SynchronizationError
}; };
use Amp\Parallel\Sync\{ Channel, ChannelledSocket }; use Amp\Parallel\Sync\{ Channel, ChannelledSocket };
use Amp\Parallel\Sync\Internal\{ ExitFailure, ExitStatus, ExitSuccess }; use Amp\Parallel\Sync\Internal\{ ExitFailure, ExitResult, ExitSuccess };
use AsyncInterop\{ Loop, Promise }; use AsyncInterop\{ Loop, Promise };
/** /**
@@ -302,9 +302,9 @@ class Fork implements Process, Strand {
try { try {
$response = yield $this->channel->receive(); $response = yield $this->channel->receive();
if (!$response instanceof ExitStatus) { if (!$response instanceof ExitResult) {
throw new SynchronizationError(\sprintf( throw new SynchronizationError(\sprintf(
'Did not receive an exit status from fork. Instead received data of type %s', 'Did not receive an exit result from fork. Instead received data of type %s',
\is_object($response) ? \get_class($response) : \gettype($response) \is_object($response) ? \get_class($response) : \gettype($response)
)); ));
} }
@@ -324,7 +324,7 @@ class Fork implements Process, Strand {
} }
return \Amp\pipe($this->channel->receive(), static function ($data) { return \Amp\pipe($this->channel->receive(), static function ($data) {
if ($data instanceof ExitStatus) { if ($data instanceof ExitResult) {
$data = $data->getResult(); $data = $data->getResult();
throw new SynchronizationError(\sprintf( throw new SynchronizationError(\sprintf(
'Forked process unexpectedly exited with result of type: %s', 'Forked process unexpectedly exited with result of type: %s',
@@ -345,8 +345,8 @@ class Fork implements Process, Strand {
throw new StatusError('The fork has not been started or has already finished.'); throw new StatusError('The fork has not been started or has already finished.');
} }
if ($data instanceof ExitStatus) { if ($data instanceof ExitResult) {
throw new \Error('Cannot send exit status objects.'); throw new \Error('Cannot send exit result objects.');
} }
return $this->channel->send($data); return $this->channel->send($data);

View File

@@ -4,7 +4,7 @@ namespace Amp\Parallel\Process;
use Amp\Coroutine; use Amp\Coroutine;
use Amp\Parallel\{ ContextException, Process as ProcessContext, StatusError, Strand, SynchronizationError }; use Amp\Parallel\{ ContextException, Process as ProcessContext, StatusError, Strand, SynchronizationError };
use Amp\Parallel\Sync\{ ChannelledSocket, Internal\ExitStatus }; use Amp\Parallel\Sync\{ ChannelledSocket, Internal\ExitResult };
use Amp\Process\Process; use Amp\Process\Process;
use AsyncInterop\Promise; use AsyncInterop\Promise;
@@ -60,7 +60,7 @@ class ChannelledProcess implements ProcessContext, Strand {
} }
return \Amp\pipe($this->channel->receive(), static function ($data) { return \Amp\pipe($this->channel->receive(), static function ($data) {
if ($data instanceof ExitStatus) { if ($data instanceof ExitResult) {
$data = $data->getResult(); $data = $data->getResult();
throw new SynchronizationError(\sprintf( throw new SynchronizationError(\sprintf(
"Process unexpectedly exited with result of type: %s", "Process unexpectedly exited with result of type: %s",
@@ -80,8 +80,8 @@ class ChannelledProcess implements ProcessContext, Strand {
throw new StatusError("The process has not been started"); throw new StatusError("The process has not been started");
} }
if ($data instanceof ExitStatus) { if ($data instanceof ExitResult) {
throw new \Error("Cannot send exit status objects"); throw new \Error("Cannot send exit result objects");
} }
return $this->channel->send($data); return $this->channel->send($data);
@@ -101,8 +101,8 @@ class ChannelledProcess implements ProcessContext, Strand {
private function doJoin(): \Generator { private function doJoin(): \Generator {
try { try {
$data = yield $this->channel->receive(); $data = yield $this->channel->receive();
if (!$data instanceof ExitStatus) { if (!$data instanceof ExitResult) {
throw new SynchronizationError("Did not receive an exit status from process"); throw new SynchronizationError("Did not receive an exit result from process");
} }
} catch (\Throwable $exception) { } catch (\Throwable $exception) {
$this->kill(); $this->kill();

View File

@@ -28,7 +28,7 @@ interface Channel {
* @throws \Amp\Parallel\SynchronizationError If the context has not been started or the context * @throws \Amp\Parallel\SynchronizationError If the context has not been started or the context
* unexpectedly ends. * unexpectedly ends.
* @throws \Amp\Parallel\ChannelException If sending on the channel fails. * @throws \Amp\Parallel\ChannelException If sending on the channel fails.
* @throws \Error If an ExitStatus object is given. * @throws \Error If an ExitResult object is given.
* @throws \Amp\Parallel\SerializationException If serializing the data fails. * @throws \Amp\Parallel\SerializationException If serializing the data fails.
*/ */
public function send($data): Promise; public function send($data): Promise;

View File

@@ -4,7 +4,7 @@ namespace Amp\Parallel\Sync\Internal;
use Amp\Parallel\PanicError; use Amp\Parallel\PanicError;
class ExitFailure implements ExitStatus { class ExitFailure implements ExitResult {
/** @var string */ /** @var string */
private $type; private $type;

View File

@@ -2,7 +2,7 @@
namespace Amp\Parallel\Sync\Internal; namespace Amp\Parallel\Sync\Internal;
interface ExitStatus { interface ExitResult {
/** /**
* @return mixed Return value of the callable given to the execution context. * @return mixed Return value of the callable given to the execution context.
* *

View File

@@ -2,7 +2,7 @@
namespace Amp\Parallel\Sync\Internal; namespace Amp\Parallel\Sync\Internal;
class ExitSuccess implements ExitStatus { class ExitSuccess implements ExitResult {
/** @var mixed */ /** @var mixed */
private $result; private $result;

View File

@@ -4,7 +4,7 @@ namespace Amp\Parallel\Threading;
use Amp\Coroutine; use Amp\Coroutine;
use Amp\Parallel\{ ContextException, StatusError, SynchronizationError, Strand }; use Amp\Parallel\{ ContextException, StatusError, SynchronizationError, Strand };
use Amp\Parallel\Sync\{ ChannelledSocket, Internal\ExitStatus }; use Amp\Parallel\Sync\{ ChannelledSocket, Internal\ExitResult };
use AsyncInterop\Promise; use AsyncInterop\Promise;
/** /**
@@ -201,8 +201,8 @@ class Thread implements Strand {
try { try {
$response = yield $this->channel->receive(); $response = yield $this->channel->receive();
if (!$response instanceof ExitStatus) { if (!$response instanceof ExitResult) {
throw new SynchronizationError('Did not receive an exit status from thread.'); throw new SynchronizationError('Did not receive an exit result from thread.');
} }
} catch (\Throwable $exception) { } catch (\Throwable $exception) {
$this->kill(); $this->kill();
@@ -223,7 +223,7 @@ class Thread implements Strand {
} }
return \Amp\pipe($this->channel->receive(), static function ($data) { return \Amp\pipe($this->channel->receive(), static function ($data) {
if ($data instanceof ExitStatus) { if ($data instanceof ExitResult) {
$data = $data->getResult(); $data = $data->getResult();
throw new SynchronizationError(\sprintf( throw new SynchronizationError(\sprintf(
'Thread unexpectedly exited with result of type: %s', 'Thread unexpectedly exited with result of type: %s',
@@ -243,8 +243,8 @@ class Thread implements Strand {
throw new StatusError('The thread has not been started or has already finished.'); throw new StatusError('The thread has not been started or has already finished.');
} }
if ($data instanceof ExitStatus) { if ($data instanceof ExitResult) {
throw new \Error('Cannot send exit status objects.'); throw new \Error('Cannot send exit result objects.');
} }
return $this->channel->send($data); return $this->channel->send($data);

View File

@@ -225,7 +225,7 @@ abstract class AbstractContextTest extends TestCase {
* @depends testSendAndReceive * @depends testSendAndReceive
* @expectedException \Error * @expectedException \Error
*/ */
public function testSendExitStatus() { public function testSendExitResult() {
Loop::execute(\Amp\wrap(function () { Loop::execute(\Amp\wrap(function () {
$context = $this->createContext(function () { $context = $this->createContext(function () {
$value = yield $this->receive(); $value = yield $this->receive();