submitTo() public method

Submit the task to the specific Worker in the Pool
public submitTo ( integer $worker, Threaded $task ) : integer
$worker integer The worker for execution
$task Threaded The task for execution
return integer the identifier of the Worker that accepted the object
Esempio n. 1
0
 public function submitTaskToWorker(AsyncTask $task, $worker)
 {
     if ($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->pool->submitTo((int) $worker, $task);
 }
Esempio n. 2
0
 public function testPoolGc()
 {
     $pool = new Pool(1, PoolTestWorker::class, [new stdClass(), new Threaded()]);
     $work = new PoolTestWork();
     $pool->submit($work);
     while (@$i++ < 2) {
         $pool->submit(new PoolTestWork());
         # nothing to assert, no exceptions please
     }
     $pool->submitTo(0, new PoolTestWork());
     # nothing to assert, no exceptions please
     /* synchronize with pool */
     $sync = new PoolTestSync();
     $pool->submit($sync);
     $sync->synchronized(function ($sync) {
         if (!$sync->finished) {
             $sync->wait();
         }
     }, $sync);
     $pool->collect(function ($task) {
         $this->assertTrue($task->isGarbage());
         return true;
     });
     $pool->shutdown();
 }