Help me understand how Pool :: collect works.
Pool :: collect - collect links to completed tasks
public void Pool::collect ( Callable $collector )
I assume that it Pool::collectregisters a function that will be called after each completes \Threaded $task. So I did:
<?php
$pool = new Pool(4);
$pool->collect($collector);
$pool->submit(new Task);
Does not work. But the following:
<?php
$pool = new Pool(4);
$pool->submit(new Task);
$pool->collect($collector);
So, I think that does Pool::collect: attaches $collectorto each previously presented \Threaded $task.
Now, when is it called exactly $collector? I guess it was called upon completion Threaded::run(). Wrong.
<?php
class Task extends Threaded {
public function run () { echo "Task complete\n"; }
}
$collector = function (\Task $task) {
echo "Collect task\n";
return true;
};
$pool = new Pool(4);
$pool->submit(new Task);
$pool->collect($collector);
$pool->shutdown();
Outputs:
Collect task
Task complete
$collectorcalled before completion Threaded::run().
The documentation says a lot. Does not mean that the event $collectorshould return a boolean value. I did not know that .
Pool:: collect . , .
1. ?