Skip to content

Commit db364c9

Browse files
committed
Use react/async for promise wait
1 parent 130c9d4 commit db364c9

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
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",
18-
"php-http/discovery": "^1.0"
18+
"php-http/discovery": "^1.0",
19+
"react/async": "^4@dev"
1920
},
2021
"require-dev": {
2122
"php-http/client-integration-tests": "^3.0",

src/Promise.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use React\EventLoop\LoopInterface;
1111
use React\Promise\PromiseInterface;
1212
use RuntimeException;
13+
use function React\Async\await;
1314

1415
/**
1516
* React promise adapter implementation.
@@ -114,13 +115,7 @@ 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();
123-
}
118+
await($this->promise);
124119

125120
if ($unwrap) {
126121
if (HttpPromise::REJECTED == $this->getState()) {

0 commit comments

Comments
 (0)