From bfc507782d9b8b3074ded478770f200da0e22635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Sat, 10 Oct 2020 11:31:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Kafka/Kafka.php | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/Kafka/Kafka.php b/Kafka/Kafka.php index c6b1ee90..de6584c6 100644 --- a/Kafka/Kafka.php +++ b/Kafka/Kafka.php @@ -63,29 +63,31 @@ class Kafka extends \Snowflake\Process\Process */ public function initCoroutine() { - $group = new WaitGroup(); - while ([$topic, $part, $message] = $this->channel->pop()) { - try { - $namespace = 'App\\Kafka\\' . ucfirst($topic) . 'Consumer'; - if (!class_exists($namespace)) { - return; - } - $class = Snowflake::createObject($namespace); - if (!($class instanceof ConsumerInterface)) { - continue; - } - $group->add(); - go(function () use ($group, $class, $topic, $part, $message) { - defer(function () use ($group) { - $group->done(); + go(function () { + $group = new WaitGroup(); + while ([$topic, $part, $message] = $this->channel->pop()) { + try { + $namespace = 'App\\Kafka\\' . ucfirst($topic) . 'Consumer'; + if (!class_exists($namespace)) { + return; + } + $class = Snowflake::createObject($namespace); + if (!($class instanceof ConsumerInterface)) { + continue; + } + $group->add(); + go(function () use ($group, $class, $topic, $part, $message) { + defer(function () use ($group) { + $group->done(); + }); + $class->onHandler(new Struct($topic, $part, $message)); }); - $class->onHandler(new Struct($topic, $part, $message)); - }); - } catch (\Throwable $exception) { - $this->application->error($exception->getMessage()); + } catch (\Throwable $exception) { + $this->application->error($exception->getMessage()); + } } - } - $group->wait(); + $group->wait(); + }); }