From 0b179f97398ccf8f744c915bd1cf6dc522945f34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Tue, 11 Oct 2022 17:35:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kiri-actor/Actor.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/kiri-actor/Actor.php b/kiri-actor/Actor.php index 3b6b8463..fbe9af92 100644 --- a/kiri-actor/Actor.php +++ b/kiri-actor/Actor.php @@ -2,6 +2,7 @@ namespace Kiri\Actor; +use Exception; use JsonSerializable; use Swoole\Coroutine; use Swoole\Coroutine\Channel; @@ -172,9 +173,13 @@ abstract class Actor implements ActorInterface, JsonSerializable /** * @return void + * @throws Exception */ public function run(): void { + if ($this->refreshInterval < 1) { + throw new Exception('Refresh interval must be greater than 1'); + } $this->setState(ActorState::BUSY); $this->init(); $this->messageId = Coroutine::create(fn() => $this->loop()); @@ -191,7 +196,12 @@ abstract class Actor implements ActorInterface, JsonSerializable if ($this->isShutdown()) { return; } - $this->onUpdate(); + + try { + $this->onUpdate(); + } catch (\Throwable $exception) { + \Kiri::getLogger()->error(throwable($exception)); + } Coroutine::sleep($this->refreshInterval / 1000);