Skip to content

Commit

Permalink
Make PromiseInterface extend Interop\Async\Promise
Browse files Browse the repository at this point in the history
  • Loading branch information
jsor committed Jan 2, 2017
1 parent 82e0d4b commit 4b42c60
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/FulfilledPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

use Interop\Async\Promise as AsyncInteropPromise;

class FulfilledPromise implements ExtendedPromiseInterface, CancellablePromiseInterface, AsyncInteropPromise
class FulfilledPromise implements ExtendedPromiseInterface, CancellablePromiseInterface
{
private $value;

public function __construct($value = null)
{
if ($value instanceof PromiseInterface || $value instanceof AsyncInteropPromise) {
if ($value instanceof AsyncInteropPromise) {
throw new \InvalidArgumentException('You cannot create React\Promise\FulfilledPromise with a promise. Use React\Promise\resolve($promiseOrValue) instead.');
}

Expand Down
4 changes: 1 addition & 3 deletions src/LazyPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace React\Promise;

use Interop\Async\Promise as AsyncInteropPromise;

class LazyPromise implements ExtendedPromiseInterface, CancellablePromiseInterface, AsyncInteropPromise
class LazyPromise implements ExtendedPromiseInterface, CancellablePromiseInterface
{
private $factory;
private $promise;
Expand Down
6 changes: 2 additions & 4 deletions src/Promise.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace React\Promise;

use Interop\Async\Promise as AsyncInteropPromise;

class Promise implements ExtendedPromiseInterface, CancellablePromiseInterface, AsyncInteropPromise
class Promise implements ExtendedPromiseInterface, CancellablePromiseInterface
{
private $canceller;
private $result;
Expand Down Expand Up @@ -95,7 +93,7 @@ public function when(callable $onResolved)
return $this->result()->when($onResolved);
}

$this->handlers[] = function (AsyncInteropPromise $promise) use ($onResolved) {
$this->handlers[] = function (PromiseInterface $promise) use ($onResolved) {
$promise->when($onResolved);
};
}
Expand Down
4 changes: 3 additions & 1 deletion src/PromiseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace React\Promise;

interface PromiseInterface
use Interop\Async\Promise as AsyncInteropPromise;

interface PromiseInterface extends AsyncInteropPromise
{
/**
* @return PromiseInterface
Expand Down
4 changes: 2 additions & 2 deletions src/RejectedPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

use Interop\Async\Promise as AsyncInteropPromise;

class RejectedPromise implements ExtendedPromiseInterface, CancellablePromiseInterface, AsyncInteropPromise
class RejectedPromise implements ExtendedPromiseInterface, CancellablePromiseInterface
{
private $reason;

public function __construct($reason = null)
{
if ($reason instanceof PromiseInterface || $reason instanceof AsyncInteropPromise) {
if ($reason instanceof AsyncInteropPromise) {
throw new \InvalidArgumentException('You cannot create React\Promise\RejectedPromise with a promise. Use React\Promise\reject($promiseOrValue) instead.');
}

Expand Down
2 changes: 1 addition & 1 deletion tests/FulfilledPromiseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ public function shouldThrowExceptionIfConstructedWithAAsyncInteropPromise()
{
$this->setExpectedException('\InvalidArgumentException');

return new FulfilledPromise(new FulfilledPromise());
return new FulfilledPromise(new SimpleFulfilledAsyncInteropTestPromise());
}
}
5 changes: 5 additions & 0 deletions tests/fixtures/SimpleFulfilledTestPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ public function then(callable $onFulfilled = null, callable $onRejected = null)
return new RejectedPromise($exception);
}
}

public function when(callable $onResolved)
{
$onResolved(null, 'foo');
}
}
5 changes: 5 additions & 0 deletions tests/fixtures/SimpleRejectedTestPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ public function then(callable $onFulfilled = null, callable $onRejected = null)
return new RejectedPromise($exception);
}
}

public function when(callable $onResolved)
{
$onResolved('foo');
}
}

0 comments on commit 4b42c60

Please sign in to comment.