You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.2 KiB

<?php
namespace AliyunMNS\Responses;
use GuzzleHttp\Promise\PromiseInterface;
use AliyunMNS\Responses\BaseResponse;
use AliyunMNS\Exception\MnsException;
use GuzzleHttp\Exception\TransferException;
use Psr\Http\Message\ResponseInterface;
class MnsPromise
{
private $response;
private $promise;
public function __construct(PromiseInterface &$promise, BaseResponse &$response)
{
$this->promise = $promise;
$this->response = $response;
}
public function isCompleted()
{
return $this->promise->getState() != 'pending';
}
public function getResponse()
{
return $this->response;
}
public function wait()
{
try {
$res = $this->promise->wait();
if ($res instanceof ResponseInterface)
{
$this->response->parseResponse($res->getStatusCode(), $res->getBody());
}
} catch (TransferException $e) {
$message = $e->getMessage();
if ($e->hasResponse()) {
$message = $e->getResponse()->getBody();
}
$this->response->parseErrorResponse($e->getCode(), $message);
}
return $this->response;
}
}
?>