@@ -93,7 +93,7 @@ $deferred = new React\Promise\Deferred();
9393$promise = $deferred->promise();
9494
9595$deferred->resolve(mixed $value = null);
96- $deferred->reject(mixed $reason = null );
96+ $deferred->reject(\Throwable|\Exception $reason);
9797```
9898
9999The ` promise ` method returns the promise of the deferred.
@@ -128,17 +128,14 @@ this promise once it is resolved.
128128#### Deferred::reject()
129129
130130``` php
131- $deferred->reject(mixed $reason = null );
131+ $deferred->reject(\Throwable|\Exception $reason);
132132```
133133
134134Rejects the promise returned by ` promise() ` , signalling that the deferred's
135135computation failed.
136136All consumers are notified by having ` $onRejected ` (which they registered via
137137` $promise->then() ` ) called with ` $reason ` .
138138
139- If ` $reason ` itself is a promise, the promise will be rejected with the outcome
140- of this promise regardless whether it fulfills or rejects.
141-
142139### PromiseInterface
143140
144141The promise interface provides the common interface for all promise
@@ -359,8 +356,7 @@ Creates a already rejected promise.
359356$promise = React\Promise\RejectedPromise($reason);
360357```
361358
362- Note, that ` $reason ` ** cannot** be a promise. It's recommended to use
363- [ reject()] ( #reject ) for creating rejected promises.
359+ Note, that ` $reason ` ** must** be a ` \Throwable ` or ` \Exception ` .
364360
365361### Functions
366362
@@ -390,20 +386,10 @@ If `$promiseOrValue` is a promise, it will be returned as is.
390386#### reject()
391387
392388``` php
393- $promise = React\Promise\reject(mixed $promiseOrValue );
389+ $promise = React\Promise\reject(\Throwable|\Exception $reason );
394390```
395391
396- Creates a rejected promise for the supplied ` $promiseOrValue ` .
397-
398- If ` $promiseOrValue ` is a value, it will be the rejection value of the
399- returned promise.
400-
401- If ` $promiseOrValue ` is a promise, its completion value will be the rejected
402- value of the returned promise.
403-
404- This can be useful in situations where you need to reject a promise without
405- throwing an exception. For example, it allows you to propagate a rejection with
406- the value of another promise.
392+ Creates a rejected promise for the supplied ` $reason ` .
407393
408394#### all()
409395
@@ -439,7 +425,9 @@ Returns a promise that will resolve when any one of the items in
439425will be the resolution value of the triggering item.
440426
441427The returned promise will only reject if * all* items in ` $promisesOrValues ` are
442- rejected. The rejection value will be an array of all rejection reasons.
428+ rejected. The rejection value will be a ` React\Promise\Exception\CompositeException `
429+ which holds all rejection reasons. The rejection reasons can be obtained with
430+ ` CompositeException::getExceptions() ` .
443431
444432The returned promise will also reject with a ` React\Promise\Exception\LengthException `
445433if ` $promisesOrValues ` contains 0 items.
@@ -457,8 +445,9 @@ triggering items.
457445
458446The returned promise will reject if it becomes impossible for ` $howMany ` items
459447to resolve (that is, when ` (count($promisesOrValues) - $howMany) + 1 ` items
460- reject). The rejection value will be an array of
461- ` (count($promisesOrValues) - $howMany) + 1 ` rejection reasons.
448+ reject). The rejection value will be a ` React\Promise\Exception\CompositeException `
449+ which holds ` (count($promisesOrValues) - $howMany) + 1 ` rejection reasons.
450+ The rejection reasons can be obtained with ` CompositeException::getExceptions() ` .
462451
463452The returned promise will also reject with a ` React\Promise\Exception\LengthException `
464453if ` $promisesOrValues ` contains less items than ` $howMany ` .
@@ -503,7 +492,7 @@ function getAwesomeResultPromise()
503492 $deferred = new React\Promise\Deferred();
504493
505494 // Execute a Node.js-style function using the callback pattern
506- computeAwesomeResultAsynchronously(function ($error, $result) use ($deferred) {
495+ computeAwesomeResultAsynchronously(function (\Exception $error, $result) use ($deferred) {
507496 if ($error) {
508497 $deferred->reject($error);
509498 } else {
@@ -520,7 +509,7 @@ getAwesomeResultPromise()
520509 function ($value) {
521510 // Deferred resolved, do something with $value
522511 },
523- function ($reason) {
512+ function (\Exception $reason) {
524513 // Deferred rejected, do something with $reason
525514 }
526515 );
@@ -701,11 +690,6 @@ getJsonResult()
701690 );
702691```
703692
704- Note that if a rejection value is not an instance of ` \Exception ` , it will be
705- wrapped in an exception of the type ` React\Promise\UnhandledRejectionException ` .
706-
707- You can get the original rejection reason by calling ` $exception->getReason() ` .
708-
709693Credits
710694-------
711695
0 commit comments