mirror of
https://github.com/danog/amp.git
synced 2024-11-26 12:04:42 +01:00
Move nowUpdateNeeded setting to getTimeout()
Essentially the same fix as @bwoebi committed, just placed at the source of the problem.
This commit is contained in:
parent
c3afc5e977
commit
b6fc1e12d4
@ -161,20 +161,15 @@ class NativeDriver extends Driver
|
||||
* @param resource[] $write
|
||||
* @param int $timeout
|
||||
*/
|
||||
private function selectStreams(array $read, array $write, $timeout)
|
||||
private function selectStreams(array $read, array $write, int $timeout)
|
||||
{
|
||||
$timeout /= self::MILLISEC_PER_SEC;
|
||||
|
||||
if (!empty($read) || !empty($write)) { // Use stream_select() if there are any streams in the loop.
|
||||
if ($timeout == 0) {
|
||||
$seconds = 0;
|
||||
$microseconds = 0;
|
||||
} elseif ($timeout > 0) {
|
||||
$this->nowUpdateNeeded = true;
|
||||
if ($timeout >= 0) {
|
||||
$seconds = (int) $timeout;
|
||||
$microseconds = (int) (($timeout - $seconds) * self::MICROSEC_PER_SEC);
|
||||
} else {
|
||||
$this->nowUpdateNeeded = true;
|
||||
$seconds = null;
|
||||
$microseconds = null;
|
||||
}
|
||||
@ -263,14 +258,13 @@ class NativeDriver extends Driver
|
||||
|
||||
if ($timeout > 0) { // Otherwise sleep with usleep() if $timeout > 0.
|
||||
\usleep($timeout * self::MICROSEC_PER_SEC);
|
||||
$this->nowUpdateNeeded = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int Milliseconds until next timer expires or -1 if there are no pending times.
|
||||
*/
|
||||
private function getTimeout()
|
||||
private function getTimeout(): int
|
||||
{
|
||||
while (!$this->timerQueue->isEmpty()) {
|
||||
list($watcher, $expiration) = $this->timerQueue->top();
|
||||
@ -288,6 +282,8 @@ class NativeDriver extends Driver
|
||||
return 0;
|
||||
}
|
||||
|
||||
$this->nowUpdateNeeded = true; // Loop will block, so trigger now update after blocking.
|
||||
|
||||
return $expiration;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user