瀏覽代碼

fix duplicate EV_TIMER_ONCE id

Ares 6 年之前
父節點
當前提交
844a4c4ffe
共有 1 個文件被更改,包括 6 次插入1 次删除
  1. 6 1
      Events/Swoole.php

+ 6 - 1
Events/Swoole.php

@@ -23,6 +23,8 @@ class Swoole implements EventInterface
 
     protected $_timerOnceMap = array();
 
+    protected $mapId = 0;
+
     protected $_fd = array();
 
     // milisecond
@@ -55,7 +57,10 @@ class Swoole implements EventInterface
             case self::EV_TIMER:
             case self::EV_TIMER_ONCE:
                 $method = self::EV_TIMER == $flag ? 'tick' : 'after';
-                $mapId = count($this->_timerOnceMap);
+                if ($this->mapId > PHP_INT_MAX) {
+                    $this->mapId = 0;
+                }
+                $mapId = $this->mapId++;
                 $timer_id = Timer::$method($fd * 1000,
                     function ($timer_id = null) use ($func, $args, $mapId) {
                         call_user_func_array($func, $args);