mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-06 01:51:51 +00:00
ServerScheduler::scheduleAsyncTask() returns the worker used (#1312)
This commit is contained in:
parent
7475aa3a18
commit
9902d29734
@ -92,9 +92,9 @@ class AsyncPool{
|
|||||||
$this->taskWorkers[$task->getTaskId()] = $worker;
|
$this->taskWorkers[$task->getTaskId()] = $worker;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function submitTask(AsyncTask $task){
|
public function submitTask(AsyncTask $task) : int{
|
||||||
if(isset($this->tasks[$task->getTaskId()]) or $task->isGarbage()){
|
if(isset($this->tasks[$task->getTaskId()]) or $task->isGarbage()){
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$selectedWorker = mt_rand(0, $this->size - 1);
|
$selectedWorker = mt_rand(0, $this->size - 1);
|
||||||
@ -107,6 +107,7 @@ class AsyncPool{
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->submitTaskToWorker($task, $selectedWorker);
|
$this->submitTaskToWorker($task, $selectedWorker);
|
||||||
|
return $selectedWorker;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function removeTask(AsyncTask $task, bool $force = false){
|
private function removeTask(AsyncTask $task, bool $force = false){
|
||||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
/**
|
/**
|
||||||
* Task scheduling related classes
|
* Task scheduling related classes
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace pocketmine\scheduler;
|
namespace pocketmine\scheduler;
|
||||||
|
|
||||||
use pocketmine\plugin\Plugin;
|
use pocketmine\plugin\Plugin;
|
||||||
@ -75,16 +76,16 @@ class ServerScheduler{
|
|||||||
*
|
*
|
||||||
* @param AsyncTask $task
|
* @param AsyncTask $task
|
||||||
*
|
*
|
||||||
* @return void
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function scheduleAsyncTask(AsyncTask $task){
|
public function scheduleAsyncTask(AsyncTask $task) : int{
|
||||||
if($task->getTaskId() !== null){
|
if($task->getTaskId() !== null){
|
||||||
throw new \UnexpectedValueException("Attempt to schedule the same AsyncTask instance twice");
|
throw new \UnexpectedValueException("Attempt to schedule the same AsyncTask instance twice");
|
||||||
}
|
}
|
||||||
$id = $this->nextId();
|
$id = $this->nextId();
|
||||||
$task->setTaskId($id);
|
$task->setTaskId($id);
|
||||||
$task->progressUpdates = new \Threaded;
|
$task->progressUpdates = new \Threaded;
|
||||||
$this->asyncPool->submitTask($task);
|
return $this->asyncPool->submitTask($task);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user