@@ -125,6 +125,8 @@ having `$onFulfilled` (which they registered via `$promise->then()`) called with
125125If ` $value ` itself is a promise, the promise will transition to the state of
126126this promise once it is resolved.
127127
128+ See also the [ ` resolve() ` function] ( #resolve ) .
129+
128130#### Deferred::reject()
129131
130132``` php
@@ -136,6 +138,8 @@ computation failed.
136138All consumers are notified by having ` $onRejected ` (which they registered via
137139` $promise->then() ` ) called with ` $reason ` .
138140
141+ See also the [ ` reject() ` function] ( #reject ) .
142+
139143### PromiseInterface
140144
141145The promise interface provides the common interface for all promise
@@ -361,6 +365,19 @@ a trusted promise that follows the state of the thenable is returned.
361365
362366If ` $promiseOrValue ` is a promise, it will be returned as is.
363367
368+ The resulting ` $promise ` implements the [ ` PromiseInterface ` ] ( #promiseinterface )
369+ and can be consumed like any other promise:
370+
371+ ``` php
372+ $promise = React\Promise\resolve(42);
373+
374+ $promise->then(function (int $result): void {
375+ var_dump($result);
376+ }, function (\Throwable $e): void {
377+ echo 'Error: ' . $e->getMessage() . PHP_EOL;
378+ });
379+ ```
380+
364381#### reject()
365382
366383``` php
@@ -374,6 +391,52 @@ both user land [`\Exception`](https://www.php.net/manual/en/class.exception.php)
374391[ ` \Error ` ] ( https://www.php.net/manual/en/class.error.php ) internal PHP errors. By enforcing ` \Throwable ` as reason to
375392reject a promise, any language error or user land exception can be used to reject a promise.
376393
394+ The resulting ` $promise ` implements the [ ` PromiseInterface ` ] ( #promiseinterface )
395+ and can be consumed like any other promise:
396+
397+ ``` php
398+ $promise = React\Promise\reject(new RuntimeException('Request failed'));
399+
400+ $promise->then(function (int $result): void {
401+ var_dump($result);
402+ }, function (\Throwable $e): void {
403+ echo 'Error: ' . $e->getMessage() . PHP_EOL;
404+ });
405+ ```
406+
407+ Note that rejected promises should always be handled similar to how any
408+ exceptions should always be caught in a ` try ` + ` catch ` block. If you remove the
409+ last reference to a rejected promise that has not been handled, it will
410+ report an unhandled promise rejection:
411+
412+ ``` php
413+ function incorrect(): int
414+ {
415+ $promise = React\Promise\reject(new RuntimeException('Request failed'));
416+
417+ // Commented out: No rejection handler registered here.
418+ // $promise->then(null, function (\Throwable $e): void { /* ignore */ });
419+
420+ // Returning from a function will remove all local variable references, hence why
421+ // this will report an unhandled promise rejection here.
422+ return 42;
423+ }
424+
425+ // Calling this function will log an error message plus its stack trace:
426+ // Unhandled promise rejection with RuntimeException: Request failed in example.php:10
427+ incorrect();
428+ ```
429+
430+ A rejected promise will be considered "handled" if you catch the rejection
431+ reason with either the [ ` then() ` method] ( #promiseinterfacethen ) , the
432+ [ ` catch() ` method] ( #promiseinterfacecatch ) , or the
433+ [ ` finally() ` method] ( #promiseinterfacefinally ) . Note that each of these methods
434+ return a new promise that may again be rejected if you re-throw an exception.
435+
436+ A rejected promise will also be considered "handled" if you abort the operation
437+ with the [ ` cancel() ` method] ( #promiseinterfacecancel ) (which in turn would
438+ usually reject the promise if it is still pending).
439+
377440#### all()
378441
379442``` php
0 commit comments