|
|
@@ -64,17 +64,20 @@ class ExtEventLoop extends \React\EventLoop\ExtEventLoop
|
|
|
case EventInterface::EV_SIGNAL:
|
|
|
return $this->addSignal($fd, $func);
|
|
|
case EventInterface::EV_TIMER:
|
|
|
+ $timer_id = ++$this->_timerIdIndex;
|
|
|
$timer_obj = $this->addPeriodicTimer($fd, function() use ($func, $args) {
|
|
|
call_user_func_array($func, $args);
|
|
|
});
|
|
|
- $this->_timerIdMap[++$this->_timerIdIndex] = $timer_obj;
|
|
|
- return $this->_timerIdIndex;
|
|
|
+ $this->_timerIdMap[$timer_id] = $timer_obj;
|
|
|
+ return $timer_id;
|
|
|
case EventInterface::EV_TIMER_ONCE:
|
|
|
- $timer_obj = $this->addTimer($fd, function() use ($func, $args) {
|
|
|
+ $timer_id = ++$this->_timerIdIndex;
|
|
|
+ $timer_obj = $this->addTimer($fd, function() use ($func, $args, $timer_id) {
|
|
|
+ unset($this->_timerIdMap[$timer_id]);
|
|
|
call_user_func_array($func, $args);
|
|
|
});
|
|
|
- $this->_timerIdMap[++$this->_timerIdIndex] = $timer_obj;
|
|
|
- return $this->_timerIdIndex;
|
|
|
+ $this->_timerIdMap[$timer_id] = $timer_obj;
|
|
|
+ return $timer_id;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
@@ -170,4 +173,14 @@ class ExtEventLoop extends \React\EventLoop\ExtEventLoop
|
|
|
$event->del();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Get timer count.
|
|
|
+ *
|
|
|
+ * @return integer
|
|
|
+ */
|
|
|
+ public function getTimerCount()
|
|
|
+ {
|
|
|
+ return count($this->_timerIdMap);
|
|
|
+ }
|
|
|
}
|