diff --git a/src/Mysql/PDO.php b/src/Mysql/PDO.php index d352971..b01ae6f 100644 --- a/src/Mysql/PDO.php +++ b/src/Mysql/PDO.php @@ -4,7 +4,6 @@ namespace Database\Mysql; use Exception; use Kiri\Abstracts\Logger; -use Kiri\Context; use Kiri\Kiri; use Kiri\Pool\StopHeartbeatCheck; use PDOStatement; @@ -67,21 +66,28 @@ class PDO implements StopHeartbeatCheck if (env('state', 'start') == 'exit') { return; } - if ($this->_timer === -1 && Context::inCoroutine()) { - $this->_timer = Timer::tick(1000, function () { - try { - if (env('state', 'start') == 'exit') { - Kiri::getDi()->get(Logger::class)->critical('timer end'); - $this->stopHeartbeatCheck(); - } - if (time() - $this->_last > 10 * 60) { - $this->stopHeartbeatCheck(); - $this->pdo = null; - } - } catch (\Throwable $throwable) { - error($throwable); - } - }); + if ($this->_timer === -1) { + $this->_timer = Timer::tick(1000, fn() => $this->waite()); + } + } + + + /** + * @throws Exception + */ + private function waite(): void + { + try { + if (env('state', 'start') == 'exit') { + Kiri::getDi()->get(Logger::class)->critical('timer end'); + $this->stopHeartbeatCheck(); + } + if (time() - $this->_last > 10 * 60) { + $this->stopHeartbeatCheck(); + $this->pdo = null; + } + } catch (\Throwable $throwable) { + error($throwable); } }