Skip to content

Commit

Permalink
AbstractCoroutine -> CoroutineTrait (fixes #67)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalloc committed Jan 5, 2014
1 parent 89b7697 commit 6c9ab92
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
use Recoil\Kernel\Strand\StrandInterface;

/**
* A base class for coroutines that keeps track of next tick state behaviour.
* A trait for coroutines that provides basic default implementations.
*/
abstract class AbstractCoroutine implements CoroutineInterface
trait CoroutineTrait
{
/**
* Initialize the coroutine.
Expand Down
4 changes: 3 additions & 1 deletion src/Recoil/Coroutine/GeneratorCoroutine.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
/**
* A coroutine wrapper for PHP generators.
*/
class GeneratorCoroutine extends AbstractCoroutine
class GeneratorCoroutine implements CoroutineInterface
{
use CoroutineTrait;

/**
* @param Generator $generator The PHP generator that implements the coroutine logic.
*/
Expand Down
4 changes: 3 additions & 1 deletion src/Recoil/Coroutine/PromiseCoroutine.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
/**
* A coroutine that resumes when a promise is fulfilled or rejected.
*/
class PromiseCoroutine extends AbstractCoroutine
class PromiseCoroutine implements CoroutineInterface
{
use CoroutineTrait;

/**
* @param PromiseInterface $promise The wrapped promise object.
*/
Expand Down
7 changes: 5 additions & 2 deletions src/Recoil/Kernel/Api/KernelApiCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
namespace Recoil\Kernel\Api;

use BadMethodCallException;
use Recoil\Coroutine\AbstractCoroutine;
use Recoil\Coroutine\CoroutineInterface;
use Recoil\Coroutine\CoroutineTrait;
use Recoil\Kernel\Strand\StrandInterface;

/**
Expand All @@ -11,8 +12,10 @@
* @see Recoil\Kernel\KernelApiInterface
* @see Recoil\Kernel\KernelInterface::api()
*/
class KernelApiCall extends AbstractCoroutine
class KernelApiCall implements CoroutineInterface
{
use CoroutineTrait;

/**
* @param string $name The name of the kernel API function to invoke.
* @param array $arguments The arguments to the kernel API function.
Expand Down
7 changes: 5 additions & 2 deletions src/Recoil/Kernel/Api/Select.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<?php
namespace Recoil\Kernel\Api;

use Recoil\Coroutine\AbstractCoroutine;
use Recoil\Coroutine\CoroutineInterface;
use Recoil\Coroutine\CoroutineTrait;
use Recoil\Kernel\Strand\StrandInterface;

/**
* Internal implementation of KernelApiInterface::select().
*
* @internal
*/
class Select extends AbstractCoroutine
class Select implements CoroutineInterface
{
use CoroutineTrait;

public function __construct(array $strands)
{
$this->waitStrands = $strands;
Expand Down
7 changes: 5 additions & 2 deletions src/Recoil/Kernel/Api/Sleep.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<?php
namespace Recoil\Kernel\Api;

use Recoil\Coroutine\AbstractCoroutine;
use Recoil\Coroutine\CoroutineInterface;
use Recoil\Coroutine\CoroutineTrait;
use Recoil\Kernel\Strand\StrandInterface;

/**
* Internal implementation of KernelApiInterface::sleep().
*
* @internal
*/
class Sleep extends AbstractCoroutine
class Sleep implements CoroutineInterface
{
use CoroutineTrait;

public function __construct($timeout)
{
$this->timeout = $timeout;
Expand Down
7 changes: 5 additions & 2 deletions src/Recoil/Kernel/Api/Timeout.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
namespace Recoil\Kernel\Api;

use Exception;
use Recoil\Coroutine\AbstractCoroutine;
use Recoil\Coroutine\CoroutineInterface;
use Recoil\Coroutine\CoroutineTrait;
use Recoil\Kernel\Exception\TimeoutException;
use Recoil\Kernel\Strand\StrandInterface;

Expand All @@ -11,8 +12,10 @@
*
* @internal
*/
class Timeout extends AbstractCoroutine
class Timeout implements CoroutineInterface
{
use CoroutineTrait;

public function __construct($timeout, $coroutine)
{
$this->timeout = $timeout;
Expand Down
7 changes: 5 additions & 2 deletions src/Recoil/Kernel/Api/WaitAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
namespace Recoil\Kernel\Api;

use Exception;
use Recoil\Coroutine\AbstractCoroutine;
use Recoil\Coroutine\CoroutineInterface;
use Recoil\Coroutine\CoroutineTrait;
use Recoil\Kernel\Exception\StrandTerminatedException;
use Recoil\Kernel\Strand\StrandInterface;

Expand All @@ -11,8 +12,10 @@
*
* @internal
*/
class WaitAll extends AbstractCoroutine
class WaitAll implements CoroutineInterface
{
use CoroutineTrait;

public function __construct(array $coroutines)
{
$this->coroutines = $coroutines;
Expand Down
7 changes: 5 additions & 2 deletions src/Recoil/Kernel/Strand/StackBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@

use Exception;
use LogicException;
use Recoil\Coroutine\AbstractCoroutine;
use Recoil\Coroutine\CoroutineInterface;
use Recoil\Coroutine\CoroutineTrait;

/**
* The base coroutine in a strand's call-stack.
*
* @internal
*/
class StackBase extends AbstractCoroutine
class StackBase implements CoroutineInterface
{
use CoroutineTrait;

/**
* Start the coroutine.
*
Expand Down
2 changes: 1 addition & 1 deletion test/suite/Coroutine/GeneratorCoroutineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/**
* @covers Recoil\Coroutine\GeneratorCoroutine
* @covers Recoil\Coroutine\AbstractCoroutine
* @covers Recoil\Coroutine\CoroutineTrait
*/
class GeneratorCoroutineTest extends PHPUnit_Framework_TestCase
{
Expand Down
2 changes: 1 addition & 1 deletion test/suite/Coroutine/PromiseCoroutineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

/**
* @covers Recoil\Coroutine\PromiseCoroutine
* @covers Recoil\Coroutine\AbstractCoroutine
* @covers Recoil\Coroutine\CoroutineTrait
*/
class PromiseCoroutineTest extends PHPUnit_Framework_TestCase
{
Expand Down

0 comments on commit 6c9ab92

Please sign in to comment.