title: How does Pool::collect works?
body: <p>Help me understand how exactly Pool::collect works.</p>
  
  <p><strong>Pool::collect — Collect references to completed tasks</strong></p>
  
  <pre><code>public void Pool::collect ( Callable $collector )
  </code></pre>
  
  <p>What I assume was: <code>Pool::collect</code> registers a function, which will be called after each <code>\Threaded $task</code> is completed. So, I did:</p>
  
  <pre><code>&lt;?php
  $pool = new Pool(4);
  $pool-&gt;collect($collector);
  $pool-&gt;submit(new Task);
  </code></pre>
  
  <p>Didn't work. But the following does:</p>
  
  <pre><code>&lt;?php
  $pool = new Pool(4);
  $pool-&gt;submit(new Task);
  $pool-&gt;collect($collector);
  </code></pre>
  
  <p>So, I guess what <code>Pool::collect</code> does is: attaches the <code>$collector</code> to each <code>\Threaded $task</code> previously submitted.</p>
  
  <p>Now, when exactly the <code>$collector</code> is called? I assume was called after <code>Threaded::run()</code> is completed. Wrong again.</p>
  
  <pre><code>&lt;?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-&gt;submit(new Task);
  $pool-&gt;collect($collector);
  $pool-&gt;shutdown();
  </code></pre>
  
  <p>Outputs:</p>
  
  <pre><code>Collect task
  Task complete
  </code></pre>
  
  <p><code>$collector</code> is called before <code>Threaded::run()</code> is completed.</p>
  
  <hr>
  
  <p>The documentation doesn't say much. Doesn't event say that the <code>$collector</code> must return a boolean value. <a href="https://stackoverflow.com/a/23384025/3333776">I didn't know that</a>.</p>
  
  <p><strong>I was trying to use Pool::collect as kind of a callback after each $task is completed. I think I'm in the wrong path.</strong></p>
  
  <p>Edit 1. <a href="http://pastebin.com/GdPgSjvH" rel="nofollow noreferrer">What about this attempt</a>?</p>