mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
Merge branch '3.5'
This commit is contained in:
commit
19fa6f5e8f
@ -46,6 +46,8 @@ class AsyncPool{
|
||||
|
||||
/** @var AsyncWorker[] */
|
||||
private $workers = [];
|
||||
/** @var int[] */
|
||||
private $workerLastUsed = [];
|
||||
|
||||
/** @var \Closure[] */
|
||||
private $workerStartHooks = [];
|
||||
@ -155,6 +157,7 @@ class AsyncPool{
|
||||
|
||||
$this->getWorker($worker)->stack($task);
|
||||
$this->taskQueues[$worker]->enqueue($task);
|
||||
$this->workerLastUsed[$worker] = time();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -253,10 +256,11 @@ class AsyncPool{
|
||||
|
||||
public function shutdownUnusedWorkers() : int{
|
||||
$ret = 0;
|
||||
$time = time();
|
||||
foreach($this->taskQueues as $i => $queue){
|
||||
if($queue->isEmpty()){
|
||||
if((!isset($this->workerLastUsed[$i]) or $this->workerLastUsed[$i] + 300 < $time) and $queue->isEmpty()){
|
||||
$this->workers[$i]->quit();
|
||||
unset($this->workers[$i], $this->taskQueues[$i]);
|
||||
unset($this->workers[$i], $this->taskQueues[$i], $this->workerLastUsed[$i]);
|
||||
$ret++;
|
||||
}
|
||||
}
|
||||
@ -289,5 +293,6 @@ class AsyncPool{
|
||||
}
|
||||
$this->workers = [];
|
||||
$this->taskQueues = [];
|
||||
$this->workerLastUsed = [];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user