变更
This commit is contained in:
+19
-3
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user