1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-02-24 10:03:27 +01:00

Updating to use latest changes from guzzle-ring

This commit is contained in:
Michael Dowling 2014-10-04 14:22:46 -07:00
parent 311122efa5
commit 31f7153885
2 changed files with 13 additions and 15 deletions

View File

@ -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))
);
}
}

View File

@ -1,9 +1,9 @@
<?php
namespace GuzzleHttp\Message;
use GuzzleHttp\Ring\MagicFutureTrait;
use GuzzleHttp\Ring\FutureInterface;
use GuzzleHttp\Ring\ValidatedDeferred;
use GuzzleHttp\Ring\Future\MagicFutureTrait;
use GuzzleHttp\Ring\Future\FutureInterface;
use GuzzleHttp\Ring\ValidatedDeferredInstance;
use GuzzleHttp\Stream\StreamInterface;
/**
@ -63,7 +63,7 @@ class FutureResponse implements ResponseInterface, FutureInterface
callable $deref,
callable $cancel = null
) {
$deferred = ValidatedDeferred::forInstance('GuzzleHttp\Message\ResponseInterface');
$deferred = new ValidatedDeferredInstance('GuzzleHttp\Message\ResponseInterface');
return new FutureResponse(
$deferred->promise(),
function () use ($deferred, $deref) {