Skip to content

Commit

Permalink
[HttpClient] improve monitoring of timeouts with AmpHttpClient
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Jun 9, 2020
1 parent d08db0f commit 548818d
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/Symfony/Component/HttpClient/Response/AmpResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,21 +173,18 @@ private static function perform(ClientState $multi, array &$responses = null): v
*/
private static function select(ClientState $multi, float $timeout): int
{
$start = microtime(true);
$remaining = $timeout;

while (true) {
self::$delay = Loop::delay(1000 * $remaining, [Loop::class, 'stop']);
Loop::run();

if (null === self::$delay) {
return 1;
$timeout += microtime(true);
self::$delay = Loop::defer(static function () use ($timeout) {
if (0 < $timeout -= microtime(true)) {
self::$delay = Loop::delay(ceil(1000 * $timeout), [Loop::class, 'stop']);
} else {
Loop::stop();
}
});

if (0 >= $remaining = $timeout - microtime(true) + $start) {
return 0;
}
}
Loop::run();

return null === self::$delay ? 1 : 0;
}

private static function generateResponse(Request $request, AmpClientState $multi, string $id, array &$info, array &$headers, CancellationTokenSource $canceller, array &$options, \Closure $onProgress, &$handle, ?LoggerInterface $logger)
Expand Down

0 comments on commit 548818d

Please sign in to comment.