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 */