pocketmine\scheduler\AsyncPool::submitTaskToWorker PHP Method

submitTaskToWorker() public method

public submitTaskToWorker ( AsyncTask $task, $worker )
$task AsyncTask
    public function submitTaskToWorker(AsyncTask $task, $worker)
    {
        if (isset($this->tasks[$task->getTaskId()]) or $task->isGarbage()) {
            return;
        }
        $worker = (int) $worker;
        if ($worker < 0 or $worker >= $this->size) {
            throw new \InvalidArgumentException("Invalid worker {$worker}");
        }
        $this->tasks[$task->getTaskId()] = $task;
        $this->workers[$worker]->stack($task);
        $this->workerUsage[$worker]++;
        $this->taskWorkers[$task->getTaskId()] = $worker;
    }

Usage Example

Esempio n. 1
0
 /**
  * Submits an asynchronous task to a specific Worker in the Pool
  *
  * @param AsyncTask $task
  * @param int       $worker
  *
  * @return void
  */
 public function scheduleAsyncTaskToWorker(AsyncTask $task, $worker)
 {
     if ($task->getTaskId() !== null) {
         throw new \UnexpectedValueException("Attempt to schedule the same AsyncTask instance twice");
     }
     $id = $this->nextId();
     $task->setTaskId($id);
     $task->progressUpdates = new \Threaded();
     $this->asyncPool->submitTaskToWorker($task, $worker);
 }
All Usage Examples Of pocketmine\scheduler\AsyncPool::submitTaskToWorker