Skip to content

Commit fef12b7

Browse files
committed
Use new promise package and make update with new interface
1 parent cde88a4 commit fef12b7

File tree

3 files changed

+13
-26
lines changed

3 files changed

+13
-26
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
],
1313
"require": {
1414
"php": ">=5.4",
15-
"php-http/httplug": "^1.0.0-alpha2",
15+
"php-http/httplug": "1.0.0-alpha3",
1616
"php-http/message-factory": "^0.4@dev",
1717
"react/http-client": "^0.4.8",
1818
"react/dns": "^0.4.1",

src/ReactHttpAdapter.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
use React\HttpClient\Response as ReactResponse;
1010
use Http\Client\HttpClient;
1111
use Http\Client\HttpAsyncClient;
12-
use Http\Client\Promise;
1312
use Http\Client\Exception\HttpException;
1413
use Http\Client\Exception\RequestException;
14+
use Http\Promise\Promise;
1515
use Http\Message\MessageFactory;
1616
use Psr\Http\Message\RequestInterface;
1717
use Psr\Http\Message\StreamInterface;
@@ -62,13 +62,8 @@ public function __construct(
6262
public function sendRequest(RequestInterface $request)
6363
{
6464
$promise = $this->sendAsyncRequest($request);
65-
$promise->wait();
6665

67-
if ($promise->getState() == Promise::REJECTED) {
68-
throw $promise->getException();
69-
}
70-
71-
return $promise->getResponse();
66+
return $promise->wait();
7267
}
7368

7469
/**

src/ReactPromiseAdapter.php

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
use React\EventLoop\LoopInterface;
66
use React\Promise\PromiseInterface as ReactPromise;
7-
use Http\Client\Promise;
87
use Http\Client\Exception;
8+
use Http\Promise\Promise;
99
use Psr\Http\Message\ResponseInterface;
1010

1111
/**
@@ -91,22 +91,6 @@ public function getState()
9191
return $this->state;
9292
}
9393

94-
/**
95-
* {@inheritdoc}
96-
*/
97-
public function getResponse()
98-
{
99-
return $this->response;
100-
}
101-
102-
/**
103-
* {@inheritdoc}
104-
*/
105-
public function getException()
106-
{
107-
return $this->exception;
108-
}
109-
11094
/**
11195
* Set EventLoop used for synchronous processing
11296
* @param LoopInterface $loop
@@ -121,13 +105,21 @@ public function setLoop(LoopInterface $loop)
121105
/**
122106
* {@inheritdoc}
123107
*/
124-
public function wait()
108+
public function wait($unwrap = true)
125109
{
126110
if (null === $this->loop) {
127111
throw new \LogicException("You must set the loop before wait!");
128112
}
129113
while (Promise::PENDING === $this->getState()) {
130114
$this->loop->tick();
131115
}
116+
117+
if ($unwrap) {
118+
if (Promise::REJECTED == $this->getState()) {
119+
throw $this->exception;
120+
}
121+
122+
return $this->response;
123+
}
132124
}
133125
}

0 commit comments

Comments
 (0)