modify plugin name

This commit is contained in:
2022-06-08 17:19:32 +08:00
parent 2a6b2a1979
commit 8f9de7a508
4 changed files with 39 additions and 13 deletions
+32 -3
View File
@@ -3,12 +3,14 @@
namespace Kiri\Rpc;
use Exception;
use Kiri\Abstracts\Component;
use Kiri\Context;
use Kiri\Exception\ConfigException;
use Kiri;
use Kiri\Abstracts\Component;
use Kiri\Annotation\Inject;
use Kiri\Events\EventProvider;
use Kiri\Exception\ConfigException;
use Kiri\Pool\Alias;
use Kiri\Pool\Pool;
use Kiri\Server\Events\OnBeforeShutdown;
use Swoole\Client;
@@ -32,6 +34,31 @@ class ClientPool extends Component
public int $waite;
#[Inject(EventProvider::class)]
public EventProvider $provider;
private array $names = [];
public function init()
{
$this->provider->on(OnBeforeShutdown::class, [$this, 'onBeforeShutdown']);
}
/**
* @return void
* @throws Exception
*/
public function onBeforeShutdown()
{
foreach ($this->names as $name) {
$this->getPool()->clean($name);
}
}
/**
* @param $config
* @param callable $callback
@@ -45,6 +72,8 @@ class ClientPool extends Component
$pool = $config['pool'] ?? ['min' => 1, 'max' => 100];
$this->names[] = $coroutineName;
return $this->getPool()->get($coroutineName, $callback, $pool['min'] ?? 1);
}