Skip to content

Commit

Permalink
Merge pull request reactphp#142 from jsor-labs/throwable-rejection-re…
Browse files Browse the repository at this point in the history
…adme-fixes

Use \Throwable exclusively in rejection function docs
  • Loading branch information
jsor committed Oct 7, 2019
2 parents 2bd3301 + 6a45c24 commit e49defd
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ $deferred = new React\Promise\Deferred();
$promise = $deferred->promise();

$deferred->resolve(mixed $value = null);
$deferred->reject(\Throwable|\Exception $reason);
$deferred->reject(\Throwable $reason);
```

The `promise` method returns the promise of the deferred.
Expand Down Expand Up @@ -132,7 +132,7 @@ this promise once it is resolved.
#### Deferred::reject()

```php
$deferred->reject(\Throwable|\Exception $reason);
$deferred->reject(\Throwable $reason);
```

Rejects the promise returned by `promise()`, signalling that the deferred's
Expand Down Expand Up @@ -234,7 +234,7 @@ $promise
// Only catch \RuntimeException instances
// All other types of errors will propagate automatically
})
->otherwise(function ($reason) {
->otherwise(function (\Throwable $reason) {
// Catch other errors
)};
```
Expand Down Expand Up @@ -270,7 +270,7 @@ Consider the following synchronous code:
```php
try {
return doSomething();
} catch(\Exception $e) {
} catch (\Throwable $e) {
return handleError($e);
} finally {
cleanup();
Expand Down Expand Up @@ -360,7 +360,7 @@ Creates a already rejected promise.
$promise = new React\Promise\RejectedPromise($reason);
```

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

### Functions

Expand Down Expand Up @@ -390,11 +390,16 @@ If `$promiseOrValue` is a promise, it will be returned as is.
#### reject()

```php
$promise = React\Promise\reject(\Throwable|\Exception $reason);
$promise = React\Promise\reject(\Throwable $reason);
```

Creates a rejected promise for the supplied `$reason`.

Note that the [`\Throwable`](https://www.php.net/manual/en/class.throwable.php) interface introduced in PHP 7 covers
both user land [`\Exception`](https://www.php.net/manual/en/class.exception.php)'s and
[`\Error`](https://www.php.net/manual/en/class.error.php) internal PHP errors. By enforcing `\Throwable` as reason to
reject a promise, any language error or user land exception can be used to reject a promise.

#### all()

```php
Expand Down Expand Up @@ -431,7 +436,7 @@ will be the resolution value of the triggering item.
The returned promise will only reject if *all* items in `$promisesOrValues` are
rejected. The rejection value will be a `React\Promise\Exception\CompositeException`
which holds all rejection reasons. The rejection reasons can be obtained with
`CompositeException::getExceptions()`.
`CompositeException::getThrowables()`.

The returned promise will also reject with a `React\Promise\Exception\LengthException`
if `$promisesOrValues` contains 0 items.
Expand Down Expand Up @@ -496,7 +501,7 @@ function getAwesomeResultPromise()
$deferred = new React\Promise\Deferred();

// Execute a Node.js-style function using the callback pattern
computeAwesomeResultAsynchronously(function (\Exception $error, $result) use ($deferred) {
computeAwesomeResultAsynchronously(function (\Throwable $error, $result) use ($deferred) {
if ($error) {
$deferred->reject($error);
} else {
Expand All @@ -513,7 +518,7 @@ getAwesomeResultPromise()
function ($value) {
// Deferred resolved, do something with $value
},
function (\Exception $reason) {
function (\Throwable $reason) {
// Deferred rejected, do something with $reason
}
);
Expand Down

0 comments on commit e49defd

Please sign in to comment.