From 4426686e542bd0137cd129a76dcd57a591bfa801 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Thu, 7 Dec 2017 21:26:55 -0600 Subject: [PATCH] Reorganize --- lib/{ => Context}/Context.php | 9 +++---- lib/{ => Context}/ContextException.php | 2 +- lib/Context/Internal/Thread.php | 5 +--- lib/Context/Process.php | 5 +--- lib/{ => Context}/StatusError.php | 2 +- lib/Context/Thread.php | 11 ++++----- lib/Sync/Channel.php | 8 +++---- lib/Sync/ExitFailure.php | 2 -- lib/Sync/ExitResult.php | 2 +- lib/{ => Sync}/PanicError.php | 2 +- lib/{ => Sync}/SynchronizationError.php | 2 +- lib/Worker/AbstractWorker.php | 10 ++++---- lib/Worker/DefaultPool.php | 8 +++---- lib/Worker/Pool.php | 2 +- test/{ => Context}/AbstractContextTest.php | 28 +++++++++++----------- test/Context/ThreadTest.php | 1 - 16 files changed, 44 insertions(+), 55 deletions(-) rename lib/{ => Context}/Context.php (59%) rename lib/{ => Context}/ContextException.php (62%) rename lib/{ => Context}/StatusError.php (58%) rename lib/{ => Sync}/PanicError.php (97%) rename lib/{ => Sync}/SynchronizationError.php (65%) rename test/{ => Context}/AbstractContextTest.php (89%) diff --git a/lib/Context.php b/lib/Context/Context.php similarity index 59% rename from lib/Context.php rename to lib/Context/Context.php index 3e2209c..e8a2108 100644 --- a/lib/Context.php +++ b/lib/Context/Context.php @@ -1,10 +1,11 @@ Resolves with the returned from the context. * - * @throws \Amp\Parallel\ContextException If the context dies unexpectedly. - * @throws \Amp\Parallel\PanicError If the context throws an uncaught exception. + * @throws \Amp\Parallel\Context\ContextException If the context dies unexpectedly. + * @throws \Amp\Parallel\Sync\PanicError If the context throws an uncaught exception. */ public function join(): Promise; } diff --git a/lib/ContextException.php b/lib/Context/ContextException.php similarity index 62% rename from lib/ContextException.php rename to lib/Context/ContextException.php index bc26df4..76e9914 100644 --- a/lib/ContextException.php +++ b/lib/Context/ContextException.php @@ -1,6 +1,6 @@ oid) { @@ -116,8 +113,8 @@ class Thread implements Context { /** * Spawns the thread and begins the thread's execution. * - * @throws \Amp\Parallel\StatusError If the thread has already been started. - * @throws \Amp\Parallel\ContextException If starting the thread was unsuccessful. + * @throws \Amp\Parallel\Context\StatusError If the thread has already been started. + * @throws \Amp\Parallel\Context\ContextException If starting the thread was unsuccessful. */ public function start() { if ($this->oid !== 0) { diff --git a/lib/Sync/Channel.php b/lib/Sync/Channel.php index 7a459ca..abc7cee 100644 --- a/lib/Sync/Channel.php +++ b/lib/Sync/Channel.php @@ -11,8 +11,8 @@ interface Channel { /** * @return \Amp\Promise * - * @throws \Amp\Parallel\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\Context\StatusError Thrown if the context has not been started. + * @throws \Amp\Parallel\Sync\SynchronizationError If the context has not been started or the context * unexpectedly ends. * @throws \Amp\Parallel\Sync\ChannelException If receiving from the channel fails. * @throws \Amp\Parallel\Sync\SerializationException If unserializing the data fails. @@ -24,8 +24,8 @@ interface Channel { * * @return \Amp\Promise 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\SynchronizationError If the context has not been started or the context + * @throws \Amp\Parallel\Context\StatusError Thrown if the context has not been started. + * @throws \Amp\Parallel\Sync\SynchronizationError If the context has not been started or the context * unexpectedly ends. * @throws \Amp\Parallel\Sync\ChannelException If sending on the channel fails. * @throws \Error If an ExitResult object is given. diff --git a/lib/Sync/ExitFailure.php b/lib/Sync/ExitFailure.php index 49b8e97..b7d70da 100644 --- a/lib/Sync/ExitFailure.php +++ b/lib/Sync/ExitFailure.php @@ -2,8 +2,6 @@ namespace Amp\Parallel\Sync; -use Amp\Parallel\PanicError; - class ExitFailure implements ExitResult { /** @var string */ private $type; diff --git a/lib/Sync/ExitResult.php b/lib/Sync/ExitResult.php index dafbb0f..66ebe82 100644 --- a/lib/Sync/ExitResult.php +++ b/lib/Sync/ExitResult.php @@ -6,7 +6,7 @@ interface ExitResult { /** * @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(); } diff --git a/lib/PanicError.php b/lib/Sync/PanicError.php similarity index 97% rename from lib/PanicError.php rename to lib/Sync/PanicError.php index 31d8174..66ed3c8 100644 --- a/lib/PanicError.php +++ b/lib/Sync/PanicError.php @@ -1,6 +1,6 @@ isRunning()) { diff --git a/lib/Worker/DefaultPool.php b/lib/Worker/DefaultPool.php index 4e1a4ad..0deda23 100644 --- a/lib/Worker/DefaultPool.php +++ b/lib/Worker/DefaultPool.php @@ -3,7 +3,7 @@ namespace Amp\Parallel\Worker; use Amp\CallableMaker; -use Amp\Parallel\StatusError; +use Amp\Parallel\Context\StatusError; use Amp\Promise; /** @@ -151,7 +151,7 @@ class DefaultPool implements Pool { * * @return \Amp\Promise 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. */ public function enqueue(Task $task): Promise { @@ -169,7 +169,7 @@ class DefaultPool implements Pool { * * @return \Amp\Promise 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 { 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. * * @return \Amp\Parallel\Worker\Worker - * @throws \Amp\Parallel\StatusError + * @throws \Amp\Parallel\Context\StatusError */ protected function pull(): Worker { if (!$this->isRunning()) { diff --git a/lib/Worker/Pool.php b/lib/Worker/Pool.php index c3c958d..17ea573 100644 --- a/lib/Worker/Pool.php +++ b/lib/Worker/Pool.php @@ -18,7 +18,7 @@ interface Pool extends 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; diff --git a/test/AbstractContextTest.php b/test/Context/AbstractContextTest.php similarity index 89% rename from test/AbstractContextTest.php rename to test/Context/AbstractContextTest.php index 3bf1e55..7ea9ca7 100644 --- a/test/AbstractContextTest.php +++ b/test/Context/AbstractContextTest.php @@ -1,6 +1,6 @@ createContext(function () { @@ -57,7 +57,7 @@ abstract class AbstractContextTest extends TestCase { } /** - * @expectedException \Amp\Parallel\StatusError + * @expectedException \Amp\Parallel\Context\StatusError */ public function testStartMultipleTimesThrowsError() { $this->assertRunTimeGreaterThan(function () { @@ -76,7 +76,7 @@ abstract class AbstractContextTest extends TestCase { } /** - * @expectedException \Amp\Parallel\PanicError + * @expectedException \Amp\Parallel\Sync\PanicError */ public function testExceptionInContextPanics() { Loop::run(function () { @@ -90,7 +90,7 @@ abstract class AbstractContextTest extends TestCase { } /** - * @expectedException \Amp\Parallel\PanicError + * @expectedException \Amp\Parallel\Sync\PanicError */ public function testReturnUnserializableDataPanics() { Loop::run(function () { @@ -117,7 +117,7 @@ abstract class AbstractContextTest extends TestCase { } /** - * @expectedException \Amp\Parallel\StatusError + * @expectedException \Amp\Parallel\Context\StatusError */ public function testJoinWithoutStartThrowsError() { Loop::run(function () { @@ -159,7 +159,7 @@ abstract class AbstractContextTest extends TestCase { /** * @depends testSendAndReceive - * @expectedException \Amp\Parallel\SynchronizationError + * @expectedException \Amp\Parallel\Sync\SynchronizationError */ public function testJoinWhenContextSendingData() { Loop::run(function () { @@ -175,7 +175,7 @@ abstract class AbstractContextTest extends TestCase { /** * @depends testSendAndReceive - * @expectedException \Amp\Parallel\StatusError + * @expectedException \Amp\Parallel\Context\StatusError */ public function testReceiveBeforeContextHasStarted() { Loop::run(function () { @@ -190,7 +190,7 @@ abstract class AbstractContextTest extends TestCase { /** * @depends testSendAndReceive - * @expectedException \Amp\Parallel\StatusError + * @expectedException \Amp\Parallel\Context\StatusError */ public function testSendBeforeContextHasStarted() { Loop::run(function () { @@ -205,7 +205,7 @@ abstract class AbstractContextTest extends TestCase { /** * @depends testSendAndReceive - * @expectedException \Amp\Parallel\SynchronizationError + * @expectedException \Amp\Parallel\Sync\SynchronizationError */ public function testReceiveWhenContextHasReturned() { 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 */ 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 */ 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 */ public function testExitingContextOnSend() { diff --git a/test/Context/ThreadTest.php b/test/Context/ThreadTest.php index f70ef79..0c5a0a6 100644 --- a/test/Context/ThreadTest.php +++ b/test/Context/ThreadTest.php @@ -4,7 +4,6 @@ namespace Amp\Parallel\Test\Context; use Amp\Loop; use Amp\Parallel\Context\Thread; -use Amp\Parallel\Test\AbstractContextTest; /** * @group threading