Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark FulfilledPromise and RejectedPromise as internal #164

Merged
merged 1 commit into from
Mar 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 2 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ Table of Contents
* [PromiseInterface::always()](#promiseinterfacealways)
* [PromiseInterface::cancel()](#promiseinterfacecancel)
* [Promise](#promise-2)
* [FulfilledPromise](#fulfilledpromise)
* [RejectedPromise](#rejectedpromise)
* [Functions](#functions)
* [resolve()](#resolve)
* [reject()](#reject)
Expand Down Expand Up @@ -144,19 +142,15 @@ All consumers are notified by having `$onRejected` (which they registered via

The promise interface provides the common interface for all promise
implementations.
See [Promise](#promise-2) for the only public implementation exposed by this
package.

A promise represents an eventual outcome, which is either fulfillment (success)
and an associated value, or rejection (failure) and an associated reason.

Once in the fulfilled or rejected state, a promise becomes immutable.
Neither its state nor its result (or error) can be modified.

#### Implementations

* [Promise](#promise-2)
* [FulfilledPromise](#fulfilledpromise)
* [RejectedPromise](#rejectedpromise)

#### PromiseInterface::then()

```php
Expand Down Expand Up @@ -341,27 +335,6 @@ with that thrown exception as the rejection reason.
The resolver function will be called immediately, the canceller function only
once all consumers called the `cancel()` method of the promise.

### FulfilledPromise

Creates a already fulfilled promise.

```php
$promise = new React\Promise\FulfilledPromise($value);
```

Note, that `$value` **cannot** be a promise. It's recommended to use
[resolve()](#resolve) for creating resolved promises.

### RejectedPromise

Creates a already rejected promise.

```php
$promise = new React\Promise\RejectedPromise($reason);
```

Note, that `$reason` **must** be a `\Throwable`.

### Functions

Useful functions for creating, joining, mapping and reducing collections of
Expand Down
11 changes: 10 additions & 1 deletion src/FulfilledPromise.php → src/Internal/FulfilledPromise.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
<?php

namespace React\Promise;
namespace React\Promise\Internal;

use React\Promise\Promise;
use React\Promise\PromiseInterface;
use function React\Promise\enqueue;
use function React\Promise\fatalError;
use function React\Promise\resolve;

/**
* @internal
*/
final class FulfilledPromise implements PromiseInterface
{
private $value;
Expand Down
12 changes: 11 additions & 1 deletion src/RejectedPromise.php → src/Internal/RejectedPromise.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
<?php

namespace React\Promise;
namespace React\Promise\Internal;

use React\Promise\Promise;
use React\Promise\PromiseInterface;
use function React\Promise\_checkTypehint;
use function React\Promise\enqueue;
use function React\Promise\fatalError;
use function React\Promise\resolve;

/**
* @internal
*/
final class RejectedPromise implements PromiseInterface
{
private $reason;
Expand Down
2 changes: 2 additions & 0 deletions src/Promise.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace React\Promise;

use React\Promise\Internal\RejectedPromise;

final class Promise implements PromiseInterface
{
private $canceller;
Expand Down
2 changes: 2 additions & 0 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace React\Promise;

use React\Promise\Exception\CompositeException;
use React\Promise\Internal\FulfilledPromise;
use React\Promise\Internal\RejectedPromise;

/**
* Creates a promise for the supplied `$promiseOrValue`.
Expand Down
2 changes: 2 additions & 0 deletions tests/FunctionResolveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace React\Promise;

use React\Promise\Internal\FulfilledPromise;
use React\Promise\Internal\RejectedPromise;
use Exception;

class FunctionResolveTest extends TestCase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<?php

namespace React\Promise;
namespace React\Promise\Internal;

use InvalidArgumentException;
use LogicException;
use React\Promise\PromiseAdapter\CallbackPromiseAdapter;
use React\Promise\PromiseTest\PromiseFulfilledTestTrait;
use React\Promise\PromiseTest\PromiseSettledTestTrait;
use React\Promise\TestCase;

class FulfilledPromiseTest extends TestCase
{
use PromiseTest\PromiseSettledTestTrait,
PromiseTest\PromiseFulfilledTestTrait;
use PromiseSettledTestTrait,
PromiseFulfilledTestTrait;

public function getPromiseTestAdapter(callable $canceller = null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<?php

namespace React\Promise;
namespace React\Promise\Internal;

use Exception;
use LogicException;
use React\Promise\PromiseAdapter\CallbackPromiseAdapter;
use React\Promise\PromiseTest\PromiseRejectedTestTrait;
use React\Promise\PromiseTest\PromiseSettledTestTrait;
use React\Promise\TestCase;

class RejectedPromiseTest extends TestCase
{
use PromiseTest\PromiseSettledTestTrait,
PromiseTest\PromiseRejectedTestTrait;
use PromiseSettledTestTrait,
PromiseRejectedTestTrait;

public function getPromiseTestAdapter(callable $canceller = null)
{
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/SimpleFulfilledTestThenable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace React\Promise;

use React\Promise\Internal\RejectedPromise;

class SimpleFulfilledTestThenable
{
public function then(callable $onFulfilled = null, callable $onRejected = null)
Expand Down