From 9d5ab6e80e19302321879e03f83046509fb2cb39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Tue, 11 Oct 2022 15:58:20 +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 | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/kiri-actor/Actor.php b/kiri-actor/Actor.php index 9bedeb67..663a6a5f 100644 --- a/kiri-actor/Actor.php +++ b/kiri-actor/Actor.php @@ -22,6 +22,12 @@ abstract class Actor implements ActorInterface, JsonSerializable private bool $isShutdown = false; + /** + * @var int + */ + private int $coroutineId = -1; + + /** * @var ActorState */ @@ -87,13 +93,23 @@ abstract class Actor implements ActorInterface, JsonSerializable public static function newActor($id): static { $actor = new static($id); - Coroutine::create(function (Actor $actor) { - $actor->run(); - }, $actor); + $actor->listen(); return $actor; } + /** + * @return void + */ + private function listen(): void + { + Coroutine::create(function (Actor $actor) { + $actor->coroutineId = Coroutine::getCid(); + $this->run(); + }, $this); + } + + /** * @return string */