@@ -119,8 +119,8 @@ Using the promise directly
119
119
If you don't want to use the callback system, you can also get the state of the promise with ``$promise->getState() ``
120
120
will return of one ``Promise::PENDING ``, ``Promise::FULFILLED `` or ``Promise::REJECTED ``.
121
121
122
- Then you can get the response of the promise if it's in ``FULFILLED `` state with `` $promise->getResponse() `` call or
123
- get the error of the promise if it's in ``REJECTED `` state with ``$promise->getRequest( ) `` call
122
+ Then you can get the response of the promise if it's in ``FULFILLED `` state or trigger the exception of the promise
123
+ if it's in ``REJECTED `` state with ``$promise->wait(true ) `` call.
124
124
125
125
.. note ::
126
126
@@ -131,6 +131,7 @@ Example
131
131
132
132
Here is a full example of a classic usage when using the ``sendAsyncRequest `` method::
133
133
134
+ use Http\Client\Exception;
134
135
use Http\Discovery\HttpAsyncClientDiscovery;
135
136
136
137
$httpAsyncClient = HttpAsyncClientDiscovery::find();
@@ -149,13 +150,11 @@ Here is a full example of a classic usage when using the ``sendAsyncRequest`` me
149
150
// Do some stuff not depending on the response, calling another request, etc ..
150
151
...
151
152
152
- // We need now the response for our final treatment
153
- $promise->wait();
154
-
155
- if (Promise::FULFILLED === $promise->getState()) {
156
- $response = $promise->getResponse();
157
- } else {
158
- throw new \Exception('Response not available');
153
+ try {
154
+ // We need now the response for our final treatment...
155
+ $response = $promise->wait(true);
156
+ } catch (Exception $e) {
157
+ // ...or catch the thrown exception
159
158
}
160
159
161
160
// Do your stuff with the response
0 commit comments