state; } /** * @param ActorState $state */ public function setState(ActorState $state): void { $this->state = $state; } /** * @return float */ public function getRunTime(): float { return microtime(true) - $this->startTime; } /** * @param string $uniqueId */ private function __construct(readonly public string $uniqueId) { $this->channel = new Channel(99); $this->startTime = microtime(true); } /** * @return void */ public function init(): void { } /** * @param $id * @return static */ public static function newActor($id): static { return new static($id); } /** * @return string */ public function getName(): string { return $this->uniqueId; } /** * @param mixed $response * @return bool */ public function write(mixed $response): bool { return $this->channel->push($response); } /** * @return void */ public function shutdown(): void { $this->isShutdown = true; $this->channel->close(); } /** * @return void */ public function run(): void { $this->setState(ActorState::BUSY); $this->init(); $this->loop(); $this->setState(ActorState::IDLE); } /** * @return mixed */ private function loop(): mixed { if ($this->channel->errCode == SWOOLE_CHANNEL_CLOSED) { $this->channel = new Channel(99); } $message = $this->channel->pop(); $this->process($message); return $this->loop(); } }