Skip to content

Commit e4f58f3

Browse files
committed
Use react/async for promise wait
Move and also bump phpunit/phpunit to require dev as it was wrongfully place in require in #52.
1 parent f7573f6 commit e4f58f3

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@
1111
}
1212
],
1313
"require": {
14-
"php": "^7.1|^8.0",
14+
"php": "^8.1",
1515
"php-http/httplug": "^2.0",
1616
"react/http": "^1.0",
1717
"react/event-loop": "^1.2",
1818
"php-http/discovery": "^1.0",
19-
"phpunit/phpunit": "^9.3.11 || ^7"
19+
"react/async": "^4"
2020
},
2121
"require-dev": {
2222
"php-http/client-integration-tests": "^3.0",
2323
"php-http/message": "^1.0",
24+
"phpunit/phpunit": "^9.5",
2425
"nyholm/psr7": "^1.3"
2526
},
2627
"provide": {

src/Promise.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Http\Promise\Promise as HttpPromise;
88
use Psr\Http\Message\RequestInterface;
99
use Psr\Http\Message\ResponseInterface;
10+
use function React\Async\await;
1011
use React\EventLoop\LoopInterface;
1112
use React\Promise\PromiseInterface;
1213
use RuntimeException;
@@ -114,12 +115,9 @@ public function getState()
114115
*/
115116
public function wait($unwrap = true)
116117
{
117-
$loop = $this->loop;
118-
while (HttpPromise::PENDING === $this->getState()) {
119-
$loop->futureTick(function () use ($loop) {
120-
$loop->stop();
121-
});
122-
$loop->run();
118+
try {
119+
await($this->promise);
120+
} catch (\Throwable) {
123121
}
124122

125123
if ($unwrap) {

0 commit comments

Comments
 (0)