diff --git a/PHPDaemon/Core/Timer.php b/PHPDaemon/Core/Timer.php index 2946ac5a..f3daf5ec 100644 --- a/PHPDaemon/Core/Timer.php +++ b/PHPDaemon/Core/Timer.php @@ -30,6 +30,10 @@ class Timer * @var integer Current timeout holder */ public $lastTimeout; + /** + * @var float Timer start time + */ + protected $startTime; /** * @var boolean Is the timer finished? */ @@ -63,6 +67,7 @@ public function __construct($cb, $timeout = null, $id = null, $priority = null) } $this->id = $id; $this->cb = $cb; + $this->startTime = microtime(true); if ($this->eventLoop === null) { $this->eventLoop = EventLoop::$instance; } @@ -98,6 +103,7 @@ public function timeout($timeout = null) $this->lastTimeout = $timeout; } $this->ev->add($this->lastTimeout / 1e6); + $this->startTime = microtime(true); } /** @@ -157,22 +163,24 @@ public function free() /** * Cancels timer by ID * @param integer|string $id Timer ID - * @return void + * @return float */ public static function cancelTimeout($id) { if (isset(self::$list[$id])) { - self::$list[$id]->cancel(); + return self::$list[$id]->cancel(); } + return 0; } /** * Cancels timer - * @return void + * @return float */ public function cancel() { $this->ev->del(); + return microtime(true) - $this->startTime; } /**