Skip to content

Commit a169a30

Browse files
[HttpClient] improve monitoring of timeouts with AmpHttpClient
1 parent bfaac06 commit a169a30

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

Response/AmpResponse.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,21 +173,18 @@ private static function perform(ClientState $multi, array &$responses = null): v
173173
*/
174174
private static function select(ClientState $multi, float $timeout): int
175175
{
176-
$start = microtime(true);
177-
$remaining = $timeout;
178-
179-
while (true) {
180-
self::$delay = Loop::delay(1000 * $remaining, [Loop::class, 'stop']);
181-
Loop::run();
182-
183-
if (null === self::$delay) {
184-
return 1;
176+
$timeout += microtime(true);
177+
self::$delay = Loop::defer(static function () use ($timeout) {
178+
if (0 < $timeout -= microtime(true)) {
179+
self::$delay = Loop::delay(ceil(1000 * $timeout), [Loop::class, 'stop']);
180+
} else {
181+
Loop::stop();
185182
}
183+
});
186184

187-
if (0 >= $remaining = $timeout - microtime(true) + $start) {
188-
return 0;
189-
}
190-
}
185+
Loop::run();
186+
187+
return null === self::$delay ? 1 : 0;
191188
}
192189

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

0 commit comments

Comments
 (0)