Skip to content

Commit

Permalink
fix actor exit
Browse files Browse the repository at this point in the history
  • Loading branch information
kiss291323003 committed Nov 14, 2023
1 parent 1fdd5aa commit 4b76c42
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/WorkerProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use EasySwoole\Component\AtomicManager;
use EasySwoole\Component\Process\Socket\AbstractUnixProcess;
use EasySwoole\Component\Process\Socket\UnixProcessConfig;
use Swoole\Coroutine;
use Swoole\Coroutine\Channel;
use Swoole\Coroutine\Socket;

Expand Down Expand Up @@ -37,15 +38,18 @@ function __construct(UnixProcessConfig $config)
public function run($arg)
{
$this->mailBox = new Channel(64);
go(function (){
while (1){
$msg = $this->mailBox->pop(-1);
//此处用来执行actor 删除
if($msg['command'] == 'exit'){
unset($this->actorList[$msg['actorId']]);
AtomicManager::getInstance()->get("{$this->actorName}.{$this->workerId}")->sub(1);
}
}
Coroutine::create(function (){
while (1){
$msg = $this->mailBox->pop(-1);
if(!is_array($msg)){
break;
}
//此处用来执行actor 删除
if($msg['command'] == 'exit'){
unset($this->actorList[$msg['actorId']]);
AtomicManager::getInstance()->get("{$this->actorName}.{$this->workerId}")->sub(1);
}
}
});
parent::run($arg);
}
Expand Down

0 comments on commit 4b76c42

Please sign in to comment.