Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
chaz6chez committed Oct 14, 2024
1 parent 7651be2 commit c4f873c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/CoroutineWebServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ public function onMessage($connection, $request, ...$params)
$waitGroup = new WaitGroup();
$waitGroup->add();
// 计数 ++
self::$_connectionCoroutineCount[$connectionId] ++;
self::$_connectionCoroutineCount[$connectionId] =
isset(self::$_connectionCoroutineCount[$connectionId])
? self::$_connectionCoroutineCount[$connectionId] ++
: 1;
// 请求消费协程
new Coroutine(function () use (&$res, $waitGroup, $params, $connectionId) {
try {
Expand Down
9 changes: 5 additions & 4 deletions src/Utils/Pool/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Workbunny\WebmanCoroutine\Utils\Pool;

use WeakReference;
use Workbunny\WebmanCoroutine\Exceptions\PoolException;
use Workerman\Worker;
use function Workbunny\WebmanCoroutine\wait_for;
Expand Down Expand Up @@ -35,7 +36,7 @@ class Pool
/**
* 元素
*
* @var object|array|null|mixed
* @var WeakReference|object|array|null|mixed
*/
protected mixed $_element;

Expand Down Expand Up @@ -129,7 +130,7 @@ public static function idle(string $name): Pool|null
$pools = self::get($name, null);
// 总是按顺序优先获取空闲
foreach ($pools as $pool) {
if ($pool->isIdle()) {
if ($pool->isIdle() and $pool->getElement()) {
return $pool;
}
}
Expand Down Expand Up @@ -247,11 +248,11 @@ public function getIndex(): int
/**
* 获取元素
*
* @return resource|object|array|mixed
* @return resource|object|array|mixed|null
*/
public function getElement(): mixed
{
return $this->_element;
return ($this->_element instanceof WeakReference) ? $this->_element->get() : $this->_element;
}

/**
Expand Down

0 comments on commit c4f873c

Please sign in to comment.