Skip to content

Commit

Permalink
feat: coroutine waitGroup并发处理
Browse files Browse the repository at this point in the history
  • Loading branch information
bingcool committed Feb 29, 2024
1 parent b7fdc27 commit 5ac9c98
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/Core/Coroutine/GoWaitGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -115,7 +115,7 @@ public static function batchParallelRunWait(array $callBacks, float $timeOut = 3
}
});
}
$result = $goWait->wait($timeOut);
$result = $goWait->wait($maxTimeOut);
return $result;
}

Expand Down
10 changes: 5 additions & 5 deletions src/Core/Coroutine/Parallel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
Expand All @@ -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 ?? []);
Expand All @@ -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
Expand Down

0 comments on commit 5ac9c98

Please sign in to comment.