diff --git a/src/Client.php b/src/Client.php index c8feae52..881e7ba8 100644 --- a/src/Client.php +++ b/src/Client.php @@ -14,7 +14,8 @@ use GuzzleHttp\Ring\Core; use GuzzleHttp\Ring\Exception\CancelledFutureAccessException; use GuzzleHttp\Ring\FutureInterface; use GuzzleHttp\Exception\RequestException; -use React\Promise\Deferred; +use React\Promise\FulfilledPromise; +use React\Promise\RejectedPromise; /** * HTTP client @@ -256,18 +257,15 @@ class Client implements ClientInterface { try { $this->fsm->run($trans); - if ($trans->response instanceof FutureInterface) { - return $trans->response; - } - // Turn the normal response into a future. - $deferred = new Deferred(); - $deferred->resolve($trans->response); - return new FutureResponse($deferred->promise()); + // Turn the normal response into a future if needed. + return $trans->response instanceof FutureInterface + ? $trans->response + : new FutureResponse(new FulfilledPromise($trans->response)); } catch (\Exception $e) { // Wrap the exception in a promise if the user asked for a future. - $deferred = new Deferred(); - $deferred->reject(RequestException::wrapException($trans->request, $e)); - return new FutureResponse($deferred->promise()); + return new FutureResponse( + new RejectedPromise(RequestException::wrapException($trans->request, $e)) + ); } } diff --git a/src/Message/FutureResponse.php b/src/Message/FutureResponse.php index e6dfaf81..ab9ab6f4 100644 --- a/src/Message/FutureResponse.php +++ b/src/Message/FutureResponse.php @@ -1,9 +1,9 @@ promise(), function () use ($deferred, $deref) {