Reorganize

This commit is contained in:
Aaron Piotrowski 2017-12-07 21:26:55 -06:00
parent 1adb63d906
commit 4426686e54
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB
16 changed files with 44 additions and 55 deletions

View File

@ -1,10 +1,11 @@
<?php <?php
namespace Amp\Parallel; namespace Amp\Parallel\Context;
use Amp\Parallel\Sync\Channel;
use Amp\Promise; use Amp\Promise;
interface Context extends Sync\Channel { interface Context extends Channel {
/** /**
* @return bool * @return bool
*/ */
@ -23,8 +24,8 @@ interface Context extends Sync\Channel {
/** /**
* @return \Amp\Promise<mixed> Resolves with the returned from the context. * @return \Amp\Promise<mixed> Resolves with the returned from the context.
* *
* @throws \Amp\Parallel\ContextException If the context dies unexpectedly. * @throws \Amp\Parallel\Context\ContextException If the context dies unexpectedly.
* @throws \Amp\Parallel\PanicError If the context throws an uncaught exception. * @throws \Amp\Parallel\Sync\PanicError If the context throws an uncaught exception.
*/ */
public function join(): Promise; public function join(): Promise;
} }

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Amp\Parallel; namespace Amp\Parallel\Context;
class ContextException extends \Exception { class ContextException extends \Exception {
} }

View File

@ -3,7 +3,6 @@
namespace Amp\Parallel\Context\Internal; namespace Amp\Parallel\Context\Internal;
use Amp\Loop; use Amp\Loop;
use Amp\Parallel\ContextException;
use Amp\Parallel\Sync\Channel; use Amp\Parallel\Sync\Channel;
use Amp\Parallel\Sync\ChannelException; use Amp\Parallel\Sync\ChannelException;
use Amp\Parallel\Sync\ChannelledSocket; use Amp\Parallel\Sync\ChannelledSocket;
@ -73,7 +72,7 @@ class Thread extends \Thread {
} }
if (!isset($autoloadPath)) { if (!isset($autoloadPath)) {
throw new ContextException("Could not locate autoload.php"); throw new \Error("Could not locate autoload.php");
} }
require $autoloadPath; require $autoloadPath;
@ -111,8 +110,6 @@ class Thread extends \Thread {
} }
/** /**
* @coroutine
*
* @param \Amp\Parallel\Sync\Channel $channel * @param \Amp\Parallel\Sync\Channel $channel
* *
* @return \Generator * @return \Generator

View File

@ -3,13 +3,10 @@
namespace Amp\Parallel\Context; namespace Amp\Parallel\Context;
use Amp\ByteStream; use Amp\ByteStream;
use Amp\Parallel\Context;
use Amp\Parallel\ContextException;
use Amp\Parallel\StatusError;
use Amp\Parallel\Sync\ChannelException; use Amp\Parallel\Sync\ChannelException;
use Amp\Parallel\Sync\ChannelledStream; use Amp\Parallel\Sync\ChannelledStream;
use Amp\Parallel\Sync\ExitResult; use Amp\Parallel\Sync\ExitResult;
use Amp\Parallel\SynchronizationError; use Amp\Parallel\Sync\SynchronizationError;
use Amp\Process\Process as BaseProcess; use Amp\Process\Process as BaseProcess;
use Amp\Promise; use Amp\Promise;
use function Amp\asyncCall; use function Amp\asyncCall;

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Amp\Parallel; namespace Amp\Parallel\Context;
class StatusError extends \Error { class StatusError extends \Error {
} }

View File

@ -3,13 +3,10 @@
namespace Amp\Parallel\Context; namespace Amp\Parallel\Context;
use Amp\Loop; use Amp\Loop;
use Amp\Parallel\Context;
use Amp\Parallel\ContextException;
use Amp\Parallel\StatusError;
use Amp\Parallel\Sync\ChannelException; use Amp\Parallel\Sync\ChannelException;
use Amp\Parallel\Sync\ChannelledSocket; use Amp\Parallel\Sync\ChannelledSocket;
use Amp\Parallel\Sync\ExitResult; use Amp\Parallel\Sync\ExitResult;
use Amp\Parallel\SynchronizationError; use Amp\Parallel\Sync\SynchronizationError;
use Amp\Promise; use Amp\Promise;
use function Amp\call; use function Amp\call;
@ -96,7 +93,7 @@ class Thread implements Context {
/** /**
* Kills the thread if it is still running. * Kills the thread if it is still running.
* *
* @throws \Amp\Parallel\ContextException * @throws \Amp\Parallel\Context\ContextException
*/ */
public function __destruct() { public function __destruct() {
if (\getmypid() === $this->oid) { if (\getmypid() === $this->oid) {
@ -116,8 +113,8 @@ class Thread implements Context {
/** /**
* Spawns the thread and begins the thread's execution. * Spawns the thread and begins the thread's execution.
* *
* @throws \Amp\Parallel\StatusError If the thread has already been started. * @throws \Amp\Parallel\Context\StatusError If the thread has already been started.
* @throws \Amp\Parallel\ContextException If starting the thread was unsuccessful. * @throws \Amp\Parallel\Context\ContextException If starting the thread was unsuccessful.
*/ */
public function start() { public function start() {
if ($this->oid !== 0) { if ($this->oid !== 0) {

View File

@ -11,8 +11,8 @@ interface Channel {
/** /**
* @return \Amp\Promise<mixed> * @return \Amp\Promise<mixed>
* *
* @throws \Amp\Parallel\StatusError Thrown if the context has not been started. * @throws \Amp\Parallel\Context\StatusError Thrown if the context has not been started.
* @throws \Amp\Parallel\SynchronizationError If the context has not been started or the context * @throws \Amp\Parallel\Sync\SynchronizationError If the context has not been started or the context
* unexpectedly ends. * unexpectedly ends.
* @throws \Amp\Parallel\Sync\ChannelException If receiving from the channel fails. * @throws \Amp\Parallel\Sync\ChannelException If receiving from the channel fails.
* @throws \Amp\Parallel\Sync\SerializationException If unserializing the data fails. * @throws \Amp\Parallel\Sync\SerializationException If unserializing the data fails.
@ -24,8 +24,8 @@ interface Channel {
* *
* @return \Amp\Promise<int> Resolves with the number of bytes sent on the channel. * @return \Amp\Promise<int> Resolves with the number of bytes sent on the channel.
* *
* @throws \Amp\Parallel\StatusError Thrown if the context has not been started. * @throws \Amp\Parallel\Context\StatusError Thrown if the context has not been started.
* @throws \Amp\Parallel\SynchronizationError If the context has not been started or the context * @throws \Amp\Parallel\Sync\SynchronizationError If the context has not been started or the context
* unexpectedly ends. * unexpectedly ends.
* @throws \Amp\Parallel\Sync\ChannelException If sending on the channel fails. * @throws \Amp\Parallel\Sync\ChannelException If sending on the channel fails.
* @throws \Error If an ExitResult object is given. * @throws \Error If an ExitResult object is given.

View File

@ -2,8 +2,6 @@
namespace Amp\Parallel\Sync; namespace Amp\Parallel\Sync;
use Amp\Parallel\PanicError;
class ExitFailure implements ExitResult { class ExitFailure implements ExitResult {
/** @var string */ /** @var string */
private $type; private $type;

View File

@ -6,7 +6,7 @@ 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.
* *
* @throws \Amp\Parallel\PanicError If the context exited with an uncaught exception. * @throws \Amp\Parallel\Sync\PanicError If the context exited with an uncaught exception.
*/ */
public function getResult(); public function getResult();
} }

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Amp\Parallel; namespace Amp\Parallel\Sync;
class PanicError extends \Error { class PanicError extends \Error {
/** @var string Class name of uncaught exception. */ /** @var string Class name of uncaught exception. */

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Amp\Parallel; namespace Amp\Parallel\Sync;
class SynchronizationError extends \Error { class SynchronizationError extends \Error {
} }

View File

@ -3,9 +3,9 @@
namespace Amp\Parallel\Worker; namespace Amp\Parallel\Worker;
use Amp\Deferred; use Amp\Deferred;
use Amp\Parallel\Context; use Amp\Parallel\Context\Context;
use Amp\Parallel\ContextException; use Amp\Parallel\Context\ContextException;
use Amp\Parallel\StatusError; use Amp\Parallel\Context\StatusError;
use Amp\Promise; use Amp\Promise;
use function Amp\call; use function Amp\call;
@ -13,7 +13,7 @@ use function Amp\call;
* Base class for most common types of task workers. * Base class for most common types of task workers.
*/ */
abstract class AbstractWorker implements Worker { abstract class AbstractWorker implements Worker {
/** @var \Amp\Parallel\Context */ /** @var \Amp\Parallel\Context\Context */
private $context; private $context;
/** @var bool */ /** @var bool */
@ -26,7 +26,7 @@ abstract class AbstractWorker implements Worker {
private $onResolve; private $onResolve;
/** /**
* @param \Amp\Parallel\Context $context * @param \Amp\Parallel\Context\Context $context
*/ */
public function __construct(Context $context) { public function __construct(Context $context) {
if ($context->isRunning()) { if ($context->isRunning()) {

View File

@ -3,7 +3,7 @@
namespace Amp\Parallel\Worker; namespace Amp\Parallel\Worker;
use Amp\CallableMaker; use Amp\CallableMaker;
use Amp\Parallel\StatusError; use Amp\Parallel\Context\StatusError;
use Amp\Promise; use Amp\Promise;
/** /**
@ -151,7 +151,7 @@ class DefaultPool implements Pool {
* *
* @return \Amp\Promise<mixed> The return value of Task::run(). * @return \Amp\Promise<mixed> The return value of Task::run().
* *
* @throws \Amp\Parallel\StatusError If the pool has not been started. * @throws \Amp\Parallel\Context\StatusError If the pool has not been started.
* @throws \Amp\Parallel\Worker\TaskException If the task throws an exception. * @throws \Amp\Parallel\Worker\TaskException If the task throws an exception.
*/ */
public function enqueue(Task $task): Promise { public function enqueue(Task $task): Promise {
@ -169,7 +169,7 @@ class DefaultPool implements Pool {
* *
* @return \Amp\Promise<int[]> Array of exit status from all workers. * @return \Amp\Promise<int[]> Array of exit status from all workers.
* *
* @throws \Amp\Parallel\StatusError If the pool has not been started. * @throws \Amp\Parallel\Context\StatusError If the pool has not been started.
*/ */
public function shutdown(): Promise { public function shutdown(): Promise {
if (!$this->isRunning()) { if (!$this->isRunning()) {
@ -223,7 +223,7 @@ class DefaultPool implements Pool {
* Pulls a worker from the pool. The worker should be put back into the pool with push() to be marked as idle. * Pulls a worker from the pool. The worker should be put back into the pool with push() to be marked as idle.
* *
* @return \Amp\Parallel\Worker\Worker * @return \Amp\Parallel\Worker\Worker
* @throws \Amp\Parallel\StatusError * @throws \Amp\Parallel\Context\StatusError
*/ */
protected function pull(): Worker { protected function pull(): Worker {
if (!$this->isRunning()) { if (!$this->isRunning()) {

View File

@ -18,7 +18,7 @@ interface Pool extends Worker {
* *
* @return \Amp\Parallel\Worker\Worker * @return \Amp\Parallel\Worker\Worker
* *
* @throws \Amp\Parallel\StatusError If the queue is not running. * @throws \Amp\Parallel\Context\StatusError If the queue is not running.
*/ */
public function get(): Worker; public function get(): Worker;

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Amp\Parallel\Test; namespace Amp\Parallel\Test\Context;
use Amp\Loop; use Amp\Loop;
use Amp\Parallel\Sync\ExitSuccess; use Amp\Parallel\Sync\ExitSuccess;
@ -10,7 +10,7 @@ abstract class AbstractContextTest extends TestCase {
/** /**
* @param callable $function * @param callable $function
* *
* @return \Amp\Parallel\Context * @return \Amp\Parallel\Context\Context
*/ */
abstract public function createContext(callable $function); abstract public function createContext(callable $function);
@ -45,7 +45,7 @@ abstract class AbstractContextTest extends TestCase {
} }
/** /**
* @expectedException \Amp\Parallel\StatusError * @expectedException \Amp\Parallel\Context\StatusError
*/ */
public function testStartWhileRunningThrowsError() { public function testStartWhileRunningThrowsError() {
$context = $this->createContext(function () { $context = $this->createContext(function () {
@ -57,7 +57,7 @@ abstract class AbstractContextTest extends TestCase {
} }
/** /**
* @expectedException \Amp\Parallel\StatusError * @expectedException \Amp\Parallel\Context\StatusError
*/ */
public function testStartMultipleTimesThrowsError() { public function testStartMultipleTimesThrowsError() {
$this->assertRunTimeGreaterThan(function () { $this->assertRunTimeGreaterThan(function () {
@ -76,7 +76,7 @@ abstract class AbstractContextTest extends TestCase {
} }
/** /**
* @expectedException \Amp\Parallel\PanicError * @expectedException \Amp\Parallel\Sync\PanicError
*/ */
public function testExceptionInContextPanics() { public function testExceptionInContextPanics() {
Loop::run(function () { Loop::run(function () {
@ -90,7 +90,7 @@ abstract class AbstractContextTest extends TestCase {
} }
/** /**
* @expectedException \Amp\Parallel\PanicError * @expectedException \Amp\Parallel\Sync\PanicError
*/ */
public function testReturnUnserializableDataPanics() { public function testReturnUnserializableDataPanics() {
Loop::run(function () { Loop::run(function () {
@ -117,7 +117,7 @@ abstract class AbstractContextTest extends TestCase {
} }
/** /**
* @expectedException \Amp\Parallel\StatusError * @expectedException \Amp\Parallel\Context\StatusError
*/ */
public function testJoinWithoutStartThrowsError() { public function testJoinWithoutStartThrowsError() {
Loop::run(function () { Loop::run(function () {
@ -159,7 +159,7 @@ abstract class AbstractContextTest extends TestCase {
/** /**
* @depends testSendAndReceive * @depends testSendAndReceive
* @expectedException \Amp\Parallel\SynchronizationError * @expectedException \Amp\Parallel\Sync\SynchronizationError
*/ */
public function testJoinWhenContextSendingData() { public function testJoinWhenContextSendingData() {
Loop::run(function () { Loop::run(function () {
@ -175,7 +175,7 @@ abstract class AbstractContextTest extends TestCase {
/** /**
* @depends testSendAndReceive * @depends testSendAndReceive
* @expectedException \Amp\Parallel\StatusError * @expectedException \Amp\Parallel\Context\StatusError
*/ */
public function testReceiveBeforeContextHasStarted() { public function testReceiveBeforeContextHasStarted() {
Loop::run(function () { Loop::run(function () {
@ -190,7 +190,7 @@ abstract class AbstractContextTest extends TestCase {
/** /**
* @depends testSendAndReceive * @depends testSendAndReceive
* @expectedException \Amp\Parallel\StatusError * @expectedException \Amp\Parallel\Context\StatusError
*/ */
public function testSendBeforeContextHasStarted() { public function testSendBeforeContextHasStarted() {
Loop::run(function () { Loop::run(function () {
@ -205,7 +205,7 @@ abstract class AbstractContextTest extends TestCase {
/** /**
* @depends testSendAndReceive * @depends testSendAndReceive
* @expectedException \Amp\Parallel\SynchronizationError * @expectedException \Amp\Parallel\Sync\SynchronizationError
*/ */
public function testReceiveWhenContextHasReturned() { public function testReceiveWhenContextHasReturned() {
Loop::run(function () { Loop::run(function () {
@ -239,7 +239,7 @@ abstract class AbstractContextTest extends TestCase {
} }
/** /**
* @expectedException \Amp\Parallel\ContextException * @expectedException \Amp\Parallel\Context\ContextException
* @expectedExceptionMessage The context stopped responding * @expectedExceptionMessage The context stopped responding
*/ */
public function testExitingContextOnJoin() { public function testExitingContextOnJoin() {
@ -254,7 +254,7 @@ abstract class AbstractContextTest extends TestCase {
} }
/** /**
* @expectedException \Amp\Parallel\ContextException * @expectedException \Amp\Parallel\Context\ContextException
* @expectedExceptionMessage The context stopped responding * @expectedExceptionMessage The context stopped responding
*/ */
public function testExitingContextOnReceive() { public function testExitingContextOnReceive() {
@ -269,7 +269,7 @@ abstract class AbstractContextTest extends TestCase {
} }
/** /**
* @expectedException \Amp\Parallel\ContextException * @expectedException \Amp\Parallel\Context\ContextException
* @expectedExceptionMessage The context went away * @expectedExceptionMessage The context went away
*/ */
public function testExitingContextOnSend() { public function testExitingContextOnSend() {

View File

@ -4,7 +4,6 @@ namespace Amp\Parallel\Test\Context;
use Amp\Loop; use Amp\Loop;
use Amp\Parallel\Context\Thread; use Amp\Parallel\Context\Thread;
use Amp\Parallel\Test\AbstractContextTest;
/** /**
* @group threading * @group threading