Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
chaz6chez committed Oct 1, 2024
1 parent 753b786 commit a19657e
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/CoroutineWebServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function onMessage($connection, $request, ...$params)
$channel->push(func_get_args());
$waitGroup = new WaitGroup();
// 根据request consumer数量创建协程
$consumerCount = config('plugin.workbunny.webman-coroutine.app.consumer_count', 1);
$consumerCount = max(1, config('plugin.workbunny.webman-coroutine.app.consumer_count', 1));
foreach (range(1, $consumerCount) as $ignored) {
$waitGroup->add();
// 请求消费协程
Expand Down
2 changes: 1 addition & 1 deletion src/Handlers/SwooleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static function onMessage(CoroutineServerInterface $app, mixed $connectio
]);
$waitGroup = new WaitGroup();
// 根据request consumer数量创建协程
$consumerCount = config('plugin.workbunny.webman-coroutine.app.consumer_count', 1);
$consumerCount = max(1, config('plugin.workbunny.webman-coroutine.app.consumer_count', 1));
foreach (range(1, $consumerCount) as $ignored) {
// 协程监听通道,消费
$res = Coroutine::create(function () use ($app, $connectionChannels, $waitGroup) {
Expand Down
2 changes: 1 addition & 1 deletion src/Handlers/SwowHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static function onMessage(CoroutineServerInterface $app, mixed $connectio
]);
$waitGroup = new WaitGroup();
// 根据request consumer数量创建协程
$consumerCount = config('plugin.workbunny.webman-coroutine.app.consumer_count', 1);
$consumerCount = max(1, config('plugin.workbunny.webman-coroutine.app.consumer_count', 1));
foreach (range(1, $consumerCount) as $ignored) {
$waitGroup->add();
// 请求消费协程
Expand Down
4 changes: 4 additions & 0 deletions src/Utils/WaitGroup/Handlers/SwooleWaitGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public function __construct()
/** @inheritdoc */
public function __destruct()
{
$count = max(1, $this->count());
foreach (range(1, $count) as $ignored) {
$this->done();
}
$this->_waitGroup = null;
}

Expand Down
3 changes: 2 additions & 1 deletion src/Utils/Worker/ServerMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ protected function __runInit__serverMethods(): void
]);
$waitGroup = new WaitGroup();
// 消费者消费
foreach (range(1, $this->getConnectionConsumerCount()) as $ignored) {
$count = max(1, $this->getConnectionConsumerCount());
foreach (range(1, $count) as $ignored) {
$waitGroup->add();
// 协程创建
$this->getCoroutine()->create(function () use ($channel, $waitGroup) {
Expand Down

0 comments on commit a19657e

Please sign in to comment.