This commit is contained in:
2021-03-02 18:16:34 +08:00
parent 104a0bfe73
commit 967bfa2b37
6 changed files with 28 additions and 8 deletions
+8
View File
@@ -9,6 +9,7 @@ use Exception;
use HttpServer\Http\Context;
use JetBrains\PhpStorm\Pure;
use Phalcon\Mvc\Model\Query\Lang;
use Snowflake\Event;
use Snowflake\Exception\ComponentException;
use Snowflake\Exception\ConfigException;
use Snowflake\Snowflake;
@@ -145,11 +146,18 @@ abstract class Pool extends Component
/**
* @param $name
* @param mixed $callback
* @throws ComponentException
* @throws Exception
*/
private function createByCallback($name, mixed $callback)
{
if ($this->creates === -1 && !is_callable($callback)) {
$this->creates = Timer::tick(1000, [$this, 'Heartbeat_detection']);
$event = Snowflake::app()->getEvent();
$event->on(Event::SERVER_WORKER_STOP, function () {
Timer::clear($this->creates);
});
}
if (!Context::hasContext('create::client::ing::' . $name)) {
$this->push($name, $this->createClient($name, $callback));