Skip to content

Commit 2dcaf60

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 c9a5649 commit 2dcaf60

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ jobs:
8585
- name: Setup PHP
8686
uses: shivammathur/setup-php@v2
8787
with:
88-
php-version: 7.4
88+
php-version: 8.1
8989
tools: composer
9090
coverage: xdebug
9191

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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
use Http\Promise\Promise as HttpPromise;
88
use Psr\Http\Message\RequestInterface;
99
use Psr\Http\Message\ResponseInterface;
10+
11+
use function React\Async\await;
12+
1013
use React\EventLoop\LoopInterface;
1114
use React\Promise\PromiseInterface;
1215
use RuntimeException;
@@ -114,12 +117,9 @@ public function getState()
114117
*/
115118
public function wait($unwrap = true)
116119
{
117-
$loop = $this->loop;
118-
while (HttpPromise::PENDING === $this->getState()) {
119-
$loop->futureTick(function () use ($loop) {
120-
$loop->stop();
121-
});
122-
$loop->run();
120+
try {
121+
await($this->promise);
122+
} catch (\Throwable) {
123123
}
124124

125125
if ($unwrap) {

0 commit comments

Comments
 (0)