Closed
Description
Here's a sample program:
<?php
require(__DIR__ . "/vendor/autoload.php");
use Gt\Fetch\Http;
use Gt\Fetch\BodyResponse;
$http = new Http();
$http->fetch("http://atlas.srv.brightflair.com/slow.php?i=1&num=2000")
->then(function(BodyResponse $response) {
if($response->ok) {
echo "Response 1 OK. Getting text..." . PHP_EOL;
return $response->text();
}
})
->then(function(string $text) {
echo "Full response 1 is " . strlen($text) . " bytes!" . PHP_EOL;
});
$http->wait();
echo "The script has completed. Has the final callback been called?";
The RequestResolver
class works a treat. The BodyResponse
is resolved as soon as the headers come back from the Curl request, so when "Response 1 OK. Getting text..." is written, the body contents is still streaming in via the React loop.
The problem is that even though the BodyResponse
is resolved (see snippet below), the outer Promise never resolves.
This runs: https://github.com/PhpGt/fetch/blob/97aaaae4f4b78dae921cca262534a885b92acbab/src/BodyResponse.php#L58-L68 , but the final ->then
does not run.