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

Use \Throwable exclusively in rejection function docs #142

Merged
merged 2 commits into from
Oct 7, 2019
Merged
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
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 = 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