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); }
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(); }