This commit is contained in:
2022-10-11 15:58:20 +08:00
parent 52624c4542
commit 9d5ab6e80e
+19 -3
View File
@@ -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
*/