<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.worker.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'worker.collect.php',
    1 => 'Worker::collect',
    2 => 'Collect references to completed tasks',
  ),
  'up' => 
  array (
    0 => 'class.worker.php',
    1 => 'Worker',
  ),
  'prev' => 
  array (
    0 => 'class.worker.php',
    1 => 'Worker',
  ),
  'next' => 
  array (
    0 => 'worker.getstacked.php',
    1 => 'Worker::getStacked',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/pthreads/worker/collect.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="worker.collect" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Worker::collect</h1>
  <p class="verinfo">(PECL pthreads &gt;= 3.0.0)</p><p class="refpurpose"><span class="refname">Worker::collect</span> &mdash; <span class="dc-title">Collect references to completed tasks</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-worker.collect-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>Worker::collect</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.callable.php" class="type Callable">Callable</a></span> <code class="parameter">$collector</code><span class="initializer"> = ?</span></span>): <span class="type"><a href="language.types.integer.php" class="type int">int</a></span></div>

  <p class="simpara">
   Allows the worker to collect references determined to be garbage by the
   optionally given collector.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-worker.collect-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <dl>
   
    <dt><code class="parameter">collector</code></dt>
    <dd>
     <span class="simpara">
      A Callable collector that returns a boolean on whether the task can be
      collected or not. Only in rare cases should a custom collector need to
      be used.
     </span>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-worker.collect-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="simpara">
   The number of remaining tasks on the worker&#039;s stack to be collected.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-worker.collect-examples">
  <h3 class="title">Esempi</h3>
  <div class="example" id="example-1">
   <p><strong>Example #1 A basic example of <span class="methodname"><strong>Worker::collect()</strong></span></strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$worker </span><span style="color: #007700">= new </span><span style="color: #0000BB">Worker</span><span style="color: #007700">();<br /><br />echo </span><span style="color: #DD0000">"There are currently </span><span style="color: #007700">{</span><span style="color: #0000BB">$worker</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">collect</span><span style="color: #007700">()}</span><span style="color: #DD0000"> tasks on the stack to be collected\n"</span><span style="color: #007700">;<br /><br />for (</span><span style="color: #0000BB">$i </span><span style="color: #007700">= </span><span style="color: #0000BB">0</span><span style="color: #007700">; </span><span style="color: #0000BB">$i </span><span style="color: #007700">&lt; </span><span style="color: #0000BB">15</span><span style="color: #007700">; ++</span><span style="color: #0000BB">$i</span><span style="color: #007700">) {<br />    </span><span style="color: #0000BB">$worker</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">stack</span><span style="color: #007700">(new class extends </span><span style="color: #0000BB">Threaded </span><span style="color: #007700">{});<br />}<br /><br />echo </span><span style="color: #DD0000">"There are </span><span style="color: #007700">{</span><span style="color: #0000BB">$worker</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">collect</span><span style="color: #007700">()}</span><span style="color: #DD0000"> tasks remaining on the stack to be collected\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$worker</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">start</span><span style="color: #007700">();<br /><br />while (</span><span style="color: #0000BB">$worker</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">collect</span><span style="color: #007700">()); </span><span style="color: #FF8000">// blocks until all tasks have finished executing<br /><br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">"There are now </span><span style="color: #007700">{</span><span style="color: #0000BB">$worker</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">collect</span><span style="color: #007700">()}</span><span style="color: #DD0000"> tasks on the stack to be collected\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$worker</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">shutdown</span><span style="color: #007700">();</span></span></code></div>
   </div>

   <div class="example-contents"><p>Il precedente esempio visualizzerà:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">There are currently 0 tasks on the stack to be collected
There are 15 tasks remaining on the stack to be collected
There are now 0 tasks on the stack to be collected</pre>
</div>
   </div>
  </div>
 </div>

</div><?php manual_footer($setup); ?>