Skip to content

Use new promise package and make update with new interface #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"require": {
"php": ">=5.4",
"php-http/httplug": "^1.0.0-alpha2",
"php-http/httplug": "1.0.0-alpha3",
"php-http/message-factory": "^0.4@dev",
"react/http-client": "^0.4.8",
"react/dns": "^0.4.1",
Expand Down
9 changes: 2 additions & 7 deletions src/ReactHttpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use React\HttpClient\Response as ReactResponse;
use Http\Client\HttpClient;
use Http\Client\HttpAsyncClient;
use Http\Client\Promise;
use Http\Client\Exception\HttpException;
use Http\Client\Exception\RequestException;
use Http\Promise\Promise;
use Http\Message\MessageFactory;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\StreamInterface;
Expand Down Expand Up @@ -62,13 +62,8 @@ public function __construct(
public function sendRequest(RequestInterface $request)
{
$promise = $this->sendAsyncRequest($request);
$promise->wait();

if ($promise->getState() == Promise::REJECTED) {
throw $promise->getException();
}

return $promise->getResponse();
return $promise->wait();
}

/**
Expand Down
28 changes: 10 additions & 18 deletions src/ReactPromiseAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use React\EventLoop\LoopInterface;
use React\Promise\PromiseInterface as ReactPromise;
use Http\Client\Promise;
use Http\Client\Exception;
use Http\Promise\Promise;
use Psr\Http\Message\ResponseInterface;

/**
Expand Down Expand Up @@ -91,22 +91,6 @@ public function getState()
return $this->state;
}

/**
* {@inheritdoc}
*/
public function getResponse()
{
return $this->response;
}

/**
* {@inheritdoc}
*/
public function getException()
{
return $this->exception;
}

/**
* Set EventLoop used for synchronous processing
* @param LoopInterface $loop
Expand All @@ -121,13 +105,21 @@ public function setLoop(LoopInterface $loop)
/**
* {@inheritdoc}
*/
public function wait()
public function wait($unwrap = true)
{
if (null === $this->loop) {
throw new \LogicException("You must set the loop before wait!");
}
while (Promise::PENDING === $this->getState()) {
$this->loop->tick();
}

if ($unwrap) {
if (Promise::REJECTED == $this->getState()) {
throw $this->exception;
}

return $this->response;
}
}
}