From e49f94984c281b2f9be1108ff2052f1e150479d0 Mon Sep 17 00:00:00 2001 From: Jan Sorgalla Date: Thu, 9 May 2019 19:44:07 +0200 Subject: [PATCH 1/2] Use \Throwable exclusively in rejection function docs Follow-up for 505cf5e. --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 728c42d1..5a04c68c 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 @@ -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 )}; ``` @@ -270,7 +270,7 @@ Consider the following synchronous code: ```php try { return doSomething(); -} catch(\Exception $e) { +} catch (\Throwable $e) { return handleError($e); } finally { cleanup(); @@ -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 @@ -390,7 +390,7 @@ 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`. @@ -431,7 +431,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. @@ -496,7 +496,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 { @@ -513,7 +513,7 @@ getAwesomeResultPromise() function ($value) { // Deferred resolved, do something with $value }, - function (\Exception $reason) { + function (\Throwable $reason) { // Deferred rejected, do something with $reason } ); From 6a45c2467f8a8c45192f0177c3dd08ae2b7d0b5a Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Sun, 6 Oct 2019 13:27:18 +0200 Subject: [PATCH 2/2] Added a short paragraph about the Exception / Throwable relation --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 5a04c68c..897a9440 100644 --- a/README.md +++ b/README.md @@ -395,6 +395,11 @@ $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