This commit is contained in:
2021-02-24 14:39:26 +08:00
parent 7cab596457
commit d24bfd6ff7
2 changed files with 200 additions and 184 deletions
+13
View File
@@ -15,6 +15,7 @@ use JetBrains\PhpStorm\Pure;
use Snowflake\Error\Logger;
use Snowflake\Exception\ComponentException;
use Snowflake\Snowflake;
use Swoole\Coroutine;
/**
* Class BaseObject
@@ -39,11 +40,23 @@ class BaseObject implements Configure
$this->init();
}
public function init()
{
}
/**
* @param array|callable $callback
* @param object $scope
*/
public function async_create(array|callable $callback, object $scope)
{
Coroutine::create($callback, $scope);
}
/**
* @return string
*/
+7 -4
View File
@@ -10,6 +10,7 @@ use Snowflake\Event;
use Snowflake\Exception\ComponentException;
use Snowflake\Exception\NotFindClassException;
use Snowflake\Snowflake;
use Swoole\Coroutine;
/**
* Class ObjectPool
@@ -81,10 +82,11 @@ class ObjectPool extends \Snowflake\Abstracts\Pool
*/
public function destruct()
{
if (empty($this->_waitRecover)) {
$this->async_create(function ($scope) {
if (empty($scope->_waitRecover)) {
return;
}
foreach ($this->_waitRecover as $name => $value) {
foreach ($scope->_waitRecover as $name => $value) {
if (empty($value)) {
continue;
}
@@ -92,10 +94,11 @@ class ObjectPool extends \Snowflake\Abstracts\Pool
if (method_exists($object, 'clean')) {
$object->clean();
}
$this->push($name, $object);
$scope->push($name, $object);
}
unset($scope->_waitRecover[$name]);
}
$this->_waitRecover = [];
}, $this);
}
}