@@ -97,7 +97,7 @@ $deferred = new React\Promise\Deferred();
97
97
$promise = $deferred->promise();
98
98
99
99
$deferred->resolve(mixed $value = null);
100
- $deferred->reject(\Throwable|\Exception $reason);
100
+ $deferred->reject(\Throwable $reason);
101
101
```
102
102
103
103
The ` promise ` method returns the promise of the deferred.
@@ -132,7 +132,7 @@ this promise once it is resolved.
132
132
#### Deferred::reject()
133
133
134
134
``` php
135
- $deferred->reject(\Throwable|\Exception $reason);
135
+ $deferred->reject(\Throwable $reason);
136
136
```
137
137
138
138
Rejects the promise returned by ` promise() ` , signalling that the deferred's
@@ -234,7 +234,7 @@ $promise
234
234
// Only catch \RuntimeException instances
235
235
// All other types of errors will propagate automatically
236
236
})
237
- ->otherwise(function ($reason) {
237
+ ->otherwise(function (\Throwable $reason) {
238
238
// Catch other errors
239
239
)};
240
240
```
@@ -270,7 +270,7 @@ Consider the following synchronous code:
270
270
``` php
271
271
try {
272
272
return doSomething();
273
- } catch(\Exception $e) {
273
+ } catch (\Throwable $e) {
274
274
return handleError($e);
275
275
} finally {
276
276
cleanup();
@@ -360,7 +360,7 @@ Creates a already rejected promise.
360
360
$promise = new React\Promise\RejectedPromise($reason);
361
361
```
362
362
363
- Note, that ` $reason ` ** must** be a ` \Throwable ` or ` \Exception ` .
363
+ Note, that ` $reason ` ** must** be a ` \Throwable ` .
364
364
365
365
### Functions
366
366
@@ -390,11 +390,16 @@ If `$promiseOrValue` is a promise, it will be returned as is.
390
390
#### reject()
391
391
392
392
``` php
393
- $promise = React\Promise\reject(\Throwable|\Exception $reason);
393
+ $promise = React\Promise\reject(\Throwable $reason);
394
394
```
395
395
396
396
Creates a rejected promise for the supplied ` $reason ` .
397
397
398
+ Note that the [ ` \Throwable ` ] ( https://www.php.net/manual/en/class.throwable.php ) interface introduced in PHP 7 covers
399
+ both user land [ ` \Exception ` ] ( https://www.php.net/manual/en/class.exception.php ) 's and
400
+ [ ` \Error ` ] ( https://www.php.net/manual/en/class.error.php ) internal PHP errors. By enforcing ` \Throwable ` as reason to
401
+ reject a promise, any language error or user land exception can be used to reject a promise.
402
+
398
403
#### all()
399
404
400
405
``` php
@@ -431,7 +436,7 @@ will be the resolution value of the triggering item.
431
436
The returned promise will only reject if * all* items in ` $promisesOrValues ` are
432
437
rejected. The rejection value will be a ` React\Promise\Exception\CompositeException `
433
438
which holds all rejection reasons. The rejection reasons can be obtained with
434
- ` CompositeException::getExceptions () ` .
439
+ ` CompositeException::getThrowables () ` .
435
440
436
441
The returned promise will also reject with a ` React\Promise\Exception\LengthException `
437
442
if ` $promisesOrValues ` contains 0 items.
@@ -496,7 +501,7 @@ function getAwesomeResultPromise()
496
501
$deferred = new React\Promise\Deferred();
497
502
498
503
// Execute a Node.js-style function using the callback pattern
499
- computeAwesomeResultAsynchronously(function (\Exception $error, $result) use ($deferred) {
504
+ computeAwesomeResultAsynchronously(function (\Throwable $error, $result) use ($deferred) {
500
505
if ($error) {
501
506
$deferred->reject($error);
502
507
} else {
@@ -513,7 +518,7 @@ getAwesomeResultPromise()
513
518
function ($value) {
514
519
// Deferred resolved, do something with $value
515
520
},
516
- function (\Exception $reason) {
521
+ function (\Throwable $reason) {
517
522
// Deferred rejected, do something with $reason
518
523
}
519
524
);
0 commit comments