diff --git a/lib/Loop/EvDriver.php b/lib/Loop/EvDriver.php index 1f6175d..2f5d690 100644 --- a/lib/Loop/EvDriver.php +++ b/lib/Loop/EvDriver.php @@ -31,7 +31,7 @@ class EvDriver extends Driver private $signals = []; /** @var int Internal timestamp for now. */ - private $now = 0; + private $now; /** @var bool */ private $nowUpdateNeeded = false; @@ -43,6 +43,8 @@ class EvDriver extends Driver { $this->handle = new \EvLoop; $this->nowOffset = (int) (\microtime(true) * self::MILLISEC_PER_SEC); + $this->now = \random_int(0, $this->nowOffset); + $this->nowOffset -= $this->now; if (self::$activeSignals === null) { self::$activeSignals = &$this->signals; diff --git a/lib/Loop/EventDriver.php b/lib/Loop/EventDriver.php index d6a5c7e..3f2402d 100644 --- a/lib/Loop/EventDriver.php +++ b/lib/Loop/EventDriver.php @@ -34,7 +34,7 @@ class EventDriver extends Driver private $nowUpdateNeeded = false; /** @var int Internal timestamp for now. */ - private $now = 0; + private $now; /** @var int Loop time offset from microtime() */ private $nowOffset; @@ -43,6 +43,8 @@ class EventDriver extends Driver { $this->handle = new \EventBase; $this->nowOffset = (int) (\microtime(true) * self::MILLISEC_PER_SEC); + $this->now = \random_int(0, $this->nowOffset); + $this->nowOffset -= $this->now; if (self::$activeSignals === null) { self::$activeSignals = &$this->signals; diff --git a/lib/Loop/NativeDriver.php b/lib/Loop/NativeDriver.php index 9d7007f..501577c 100644 --- a/lib/Loop/NativeDriver.php +++ b/lib/Loop/NativeDriver.php @@ -34,7 +34,7 @@ class NativeDriver extends Driver private $nowUpdateNeeded = false; /** @var int Internal timestamp for now. */ - private $now = 0; + private $now; /** @var int Loop time offset from microtime() */ private $nowOffset; @@ -47,6 +47,8 @@ class NativeDriver extends Driver $this->timerQueue = new \SplPriorityQueue(); $this->signalHandling = \extension_loaded("pcntl"); $this->nowOffset = (int) (\microtime(true) * self::MILLISEC_PER_SEC); + $this->now = \random_int(0, $this->nowOffset); + $this->nowOffset -= $this->now; } /** @@ -126,6 +128,10 @@ class NativeDriver extends Driver // Execute the timer. $result = ($watcher->callback)($id, $watcher->data); + if ($result === null) { + continue; + } + if ($result instanceof \Generator) { $result = new Coroutine($result); }