变更
This commit is contained in:
+19
-3
@@ -22,6 +22,12 @@ abstract class Actor implements ActorInterface, JsonSerializable
|
|||||||
private bool $isShutdown = false;
|
private bool $isShutdown = false;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private int $coroutineId = -1;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ActorState
|
* @var ActorState
|
||||||
*/
|
*/
|
||||||
@@ -87,13 +93,23 @@ abstract class Actor implements ActorInterface, JsonSerializable
|
|||||||
public static function newActor($id): static
|
public static function newActor($id): static
|
||||||
{
|
{
|
||||||
$actor = new static($id);
|
$actor = new static($id);
|
||||||
Coroutine::create(function (Actor $actor) {
|
$actor->listen();
|
||||||
$actor->run();
|
|
||||||
}, $actor);
|
|
||||||
return $actor;
|
return $actor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function listen(): void
|
||||||
|
{
|
||||||
|
Coroutine::create(function (Actor $actor) {
|
||||||
|
$actor->coroutineId = Coroutine::getCid();
|
||||||
|
$this->run();
|
||||||
|
}, $this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user