From 5ac9c986ee4d0aa7d0a778690c7a887ce3aab194 Mon Sep 17 00:00:00 2001 From: bingcool <2437667702@qq.com> Date: Thu, 29 Feb 2024 20:05:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20coroutine=20waitGroup=E5=B9=B6=E5=8F=91?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Core/Coroutine/GoWaitGroup.php | 6 +++--- src/Core/Coroutine/Parallel.php | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Core/Coroutine/GoWaitGroup.php b/src/Core/Coroutine/GoWaitGroup.php index b3355e80..5cbae76b 100644 --- a/src/Core/Coroutine/GoWaitGroup.php +++ b/src/Core/Coroutine/GoWaitGroup.php @@ -96,10 +96,10 @@ public function goApp(\Closure $callBack, ...$params) * var_dump($result); * * @param array $callBacks - * @param float $timeOut + * @param float $maxTimeOut * @return array */ - public static function batchParallelRunWait(array $callBacks, float $timeOut = 3.0): array + public static function batchParallelRunWait(array $callBacks, float $maxTimeOut = 3.0): array { $goWait = new static(); foreach ($callBacks as $key => $callBack) { @@ -115,7 +115,7 @@ public static function batchParallelRunWait(array $callBacks, float $timeOut = 3 } }); } - $result = $goWait->wait($timeOut); + $result = $goWait->wait($maxTimeOut); return $result; } diff --git a/src/Core/Coroutine/Parallel.php b/src/Core/Coroutine/Parallel.php index 19d9006b..8b50bd14 100644 --- a/src/Core/Coroutine/Parallel.php +++ b/src/Core/Coroutine/Parallel.php @@ -73,10 +73,10 @@ public function add(callable $callable, string $key = null) /** * runWait 并发后等待结果返回 * - * @param float $timeOut + * @param float $maxTimeOut * @return array */ - public function runWait(float $timeOut = 5.0) + public function runWait(float $maxTimeOut = 5.0) { if (empty($this->callbacks)) { return []; @@ -96,7 +96,7 @@ public function runWait(float $timeOut = 5.0) } if ($items) { - $res = GoWaitGroup::batchParallelRunWait($items, $timeOut); + $res = GoWaitGroup::batchParallelRunWait($items, $maxTimeOut); } $result = array_merge($result, $res ?? []); @@ -106,9 +106,9 @@ public function runWait(float $timeOut = 5.0) } /** - * 并发限制协程数量闭包处理 + * 并发限制协程数量闭包处理,无需等待结果返回 * - * @param int $concurrent 限制的并发协程数量 + * @param int $concurrent 限制的每批并发协程数量,防止瞬间产生大量的协程拖垮下游服务或者DB * @param array $list 数组 * @param \Closure $handleFn 回调处理 * @param float $sleepTime