From f43b3ddbd7e3ff1d0a5eb567552cfb422728f156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Fri, 9 Oct 2020 16:56:00 +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 --- HttpServer/Server.php | 6 +++++- System/Process/Process.php | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/HttpServer/Server.php b/HttpServer/Server.php index 10f2ed0c..1b45a3cf 100644 --- a/HttpServer/Server.php +++ b/HttpServer/Server.php @@ -214,7 +214,11 @@ class Server extends Application if (!is_string($process)) { continue; } - $system = new $process(Snowflake::app(), $name); + $is_enable_coroutine = true; + if (is_array($process)) { + [$process, $is_enable_coroutine] = $process; + } + $system = new $process(Snowflake::app(), $name, $is_enable_coroutine); $this->baseServer->addProcess($system); $application->set($process, $system); } diff --git a/System/Process/Process.php b/System/Process/Process.php index 5358a0a6..74e2d443 100644 --- a/System/Process/Process.php +++ b/System/Process/Process.php @@ -26,9 +26,10 @@ abstract class Process extends \Swoole\Process * Process constructor. * @param $application * @param $name + * @param bool $enable_coroutine * @throws \Exception */ - public function __construct($application, $name) + public function __construct($application, $name, $enable_coroutine = true) { $class = get_called_class(); parent::__construct(function ($process) use ($name, $class) { @@ -36,7 +37,7 @@ abstract class Process extends \Swoole\Process $this->name('Processes: ' . $class . '::class'); } $this->onHandler($process); - }, false, 1, true); + }, false, 1, $enable_coroutine); $this->application = $application; Snowflake::setWorkerId($this->pid); }