diff --git a/src/Traits/ChannelMethods.php b/src/Traits/ChannelMethods.php index 7001d06..23af34d 100644 --- a/src/Traits/ChannelMethods.php +++ b/src/Traits/ChannelMethods.php @@ -25,11 +25,6 @@ trait ChannelMethods */ protected static array $_listeners = []; - /** - * @var array = [channelKey => callback] - */ - protected static array $_listenerCallbacks = []; - /** * @var float|int|null */ @@ -156,17 +151,16 @@ protected static function _ChCreateListener(string $key, string|int $workerId, C // 设置回调 $channel[$workerId]['futureId'] = - self::$_listenerCallbacks[$key] = $listener; self::$_listeners[$key] = - $result = Future::add(function () use ($key, $workerId) { + $result = Future::add(function () use ($key, $workerId, $listener) { // 原子性执行 - self::_Atomic($key, function () use ($key, $workerId) { + self::_Atomic($key, function () use ($key, $workerId, $listener) { $channel = self::_Get($channelName = self::GetChannelKey($key), []); if ((!empty($value = $channel[$workerId]['value'] ?? []))) { // 先进先出 $msg = array_shift($value); $channel[$workerId]['value'] = $value; - call_user_func(self::$_listenerCallbacks[$key], $key, $workerId, $msg); + call_user_func($listener, $key, $workerId, $msg); self::_Set($channelName, $channel); } @@ -221,7 +215,7 @@ protected static function _ChRemoveListener(string $key, string|int $workerId, b unset($channel[$workerId]); self::_Set($channelName, $channel); } - unset(self::$_listeners[$key], self::$_listenerCallbacks[$key]); + unset(self::$_listeners[$key]); } return [