This commit is contained in:
2020-10-10 11:33:11 +08:00
parent bfc507782d
commit 4bb06ef42d
+3 -5
View File
@@ -38,7 +38,7 @@ class Kafka extends \Snowflake\Process\Process
$config->setTopics($kafka['topics']); $config->setTopics($kafka['topics']);
$this->channel = new Channel(1000); $this->channel = new Channel(1000);
$this->initCoroutine(); go([$this, 'listener']);
} }
@@ -59,11 +59,10 @@ class Kafka extends \Snowflake\Process\Process
/** /**
* * 监听通道数据传递
*/ */
public function initCoroutine() protected function listener()
{ {
go(function () {
$group = new WaitGroup(); $group = new WaitGroup();
while ([$topic, $part, $message] = $this->channel->pop()) { while ([$topic, $part, $message] = $this->channel->pop()) {
try { try {
@@ -87,7 +86,6 @@ class Kafka extends \Snowflake\Process\Process
} }
} }
$group->wait(); $group->wait();
});
} }