改名
This commit is contained in:
@@ -26,7 +26,7 @@ abstract class Pool extends Component
|
|||||||
/** @var Channel[] */
|
/** @var Channel[] */
|
||||||
private array $_items = [];
|
private array $_items = [];
|
||||||
|
|
||||||
protected int $max = 60;
|
public int $max = 60;
|
||||||
|
|
||||||
use Timeout;
|
use Timeout;
|
||||||
|
|
||||||
|
|||||||
@@ -19,23 +19,7 @@ use Swoole\Coroutine;
|
|||||||
class ObjectPool extends \Snowflake\Abstracts\Pool
|
class ObjectPool extends \Snowflake\Abstracts\Pool
|
||||||
{
|
{
|
||||||
|
|
||||||
private array $_waitRecover = [];
|
public int $max = 5000;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ObjectPool constructor.
|
|
||||||
* @param array $config
|
|
||||||
* @throws ComponentException
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function __construct($config = [])
|
|
||||||
{
|
|
||||||
$this->max = 5000;
|
|
||||||
|
|
||||||
listen(Event::SYSTEM_RESOURCE_RELEASES, [$this, 'destruct']);
|
|
||||||
|
|
||||||
parent::__construct($config);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,7 +33,11 @@ class ObjectPool extends \Snowflake\Abstracts\Pool
|
|||||||
if (is_object($config)) {
|
if (is_object($config)) {
|
||||||
return $config;
|
return $config;
|
||||||
}
|
}
|
||||||
return $this->getFromChannel($name = md5($config), [$config, $construct]);
|
$object = $this->getFromChannel($name = md5($config), [$config, $construct]);
|
||||||
|
if (method_exists($object, 'clean')) {
|
||||||
|
$object->clean();
|
||||||
|
}
|
||||||
|
return $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -70,35 +58,7 @@ class ObjectPool extends \Snowflake\Abstracts\Pool
|
|||||||
*/
|
*/
|
||||||
public function release(string $name, mixed $object)
|
public function release(string $name, mixed $object)
|
||||||
{
|
{
|
||||||
if (!isset($this->_waitRecover[$name])) {
|
$this->push($name, $object);
|
||||||
$this->_waitRecover[$name] = [];
|
|
||||||
}
|
|
||||||
$this->_waitRecover[$name][] = $object;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 清理等待回收的对象
|
|
||||||
*/
|
|
||||||
public function destruct()
|
|
||||||
{
|
|
||||||
$this->async_create(function ($scope) {
|
|
||||||
if (empty($scope->_waitRecover)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
foreach ($scope->_waitRecover as $name => $value) {
|
|
||||||
if (empty($value)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
foreach ($value as $object) {
|
|
||||||
if (method_exists($object, 'clean')) {
|
|
||||||
$object->clean();
|
|
||||||
}
|
|
||||||
$scope->push($name, $object);
|
|
||||||
}
|
|
||||||
unset($scope->_waitRecover[$name]);
|
|
||||||
}
|
|
||||||
}, $this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user