I use Guzzle 6 to call asynchrous request and I then use React Promise/Deferred and Event loop , then I use php-react-block to get result by resolved.
Firstly I send http Request as following:
public function callService($endpoint){
$requestDeferred = new React\Promise\Deferred();
$requestParams = new Request("POST", $endpoint, $header, $message);
$client = new Client();//Guzzle http client
$client->sendAsync($requestParams)->then(
function (ResponseInterface $res) use($requestDeferred) {
// $res->getStatusCode() . "\n";
$requestDeferred->resolve($res->getBody()->getContents());
},
function (RequestException $e) use($requestDeferred) {
$requestDeferred->reject();
}
);
return $requestDeferred->promise();
}
After I call this method as following
$loop = React\EventLoop\Factory::create();
$requestPromise = $this->callService( $endpoint);
$responseXml = Clue\React\Block\await($requestPromise, $loop);// I want to block/wait to until promise is resolved and get resolved value.
But when I call Clue\React\Block\await($requestPromise, $loop) , the system loops infinetly and any promise can not be resolved. Also I added queue->run() method to run method of related event (LibEvent). But system still loops infinetly.
Why the system loops infinetly?
Thanks for your helps