Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions PHPDaemon/Core/Timer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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?
*/
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -98,6 +103,7 @@ public function timeout($timeout = null)
$this->lastTimeout = $timeout;
}
$this->ev->add($this->lastTimeout / 1e6);
$this->startTime = microtime(true);
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand Down