变更
This commit is contained in:
+11
-1
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Kiri\Actor;
|
namespace Kiri\Actor;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use JsonSerializable;
|
use JsonSerializable;
|
||||||
use Swoole\Coroutine;
|
use Swoole\Coroutine;
|
||||||
use Swoole\Coroutine\Channel;
|
use Swoole\Coroutine\Channel;
|
||||||
@@ -172,9 +173,13 @@ abstract class Actor implements ActorInterface, JsonSerializable
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
|
if ($this->refreshInterval < 1) {
|
||||||
|
throw new Exception('Refresh interval must be greater than 1');
|
||||||
|
}
|
||||||
$this->setState(ActorState::BUSY);
|
$this->setState(ActorState::BUSY);
|
||||||
$this->init();
|
$this->init();
|
||||||
$this->messageId = Coroutine::create(fn() => $this->loop());
|
$this->messageId = Coroutine::create(fn() => $this->loop());
|
||||||
@@ -191,7 +196,12 @@ abstract class Actor implements ActorInterface, JsonSerializable
|
|||||||
if ($this->isShutdown()) {
|
if ($this->isShutdown()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->onUpdate();
|
|
||||||
|
try {
|
||||||
|
$this->onUpdate();
|
||||||
|
} catch (\Throwable $exception) {
|
||||||
|
\Kiri::getLogger()->error(throwable($exception));
|
||||||
|
}
|
||||||
|
|
||||||
Coroutine::sleep($this->refreshInterval / 1000);
|
Coroutine::sleep($this->refreshInterval / 1000);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user