Skip to content

Commit

Permalink
Fixed a bug where channels could not specify workerId publication
Browse files Browse the repository at this point in the history
  • Loading branch information
chaz6chez committed May 17, 2024
1 parent df45fcc commit b1ca99f
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/Traits/ChannelMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected static function _ChPublish(string $key, mixed $message, bool $store =
$func = __FUNCTION__;
$params = func_get_args();
self::_Atomic($key, function () use (
$key, $message, $func, $params, $store
$key, $message, $func, $params, $store, $workerId
) {
/**
* [
Expand All @@ -94,16 +94,33 @@ protected static function _ChPublish(string $key, mixed $message, bool $store =
// 如果还没有监听器,将数据投入默认
if (!$channel) {
if ($store) {
$channel['--default--']['value'][] = $message;
// 非指定workerId
if ($workerId !== null) {
$channel['--default--']['value'][] = $message;
}
// 指定workerId
else {
$channel[$workerId]['value'][] = $message;
}

}
}
// 否则将消息投入到每个worker的监听器数据中
else {
foreach ($channel as $workerId => $item) {
if ($store or isset($item['futureId'])) {
// 非指定workerId
if ($workerId !== null) {
if ($store or isset($channel[$workerId]['futureId'])) {
$channel[$workerId]['value'][] = $message;
}
}
// 指定workerId
else {
foreach ($channel as $workerId => $item) {
if ($store or isset($item['futureId'])) {
$channel[$workerId]['value'][] = $message;
}
}
}
}

self::_Set($channelName, $channel);
Expand Down

0 comments on commit b1ca99f

Please sign in to comment.