PHP - Fonction Pool :: collect ()

La fonction Pool :: collect () peut collecter des références aux tâches terminées.

Syntaxe

public int Pool::collect([ Callable $collector ] )

La fonction Pool :: collect () peut permettre à un pool de collecter des références déterminées comme étant des déchets par un collecteur éventuellement donné.

La fonction Pool :: collect () peut retourner le nombre de tâches restantes dans un pool à collecter.

Exemple

<?php
   class MyWork extends Stackable {
      public function __construct() {
         $this->complete = false;
      }
      public function run() {
         printf("Hello from %s in Thread #%lu\n", __CLASS__, $this->worker->getThreadId());
         $this->complete = true;
      }
      public function isComplete() { 
         return $this->complete; 
      }
      protected $complete;
   }
   class MyWorker extends Worker {
      public function __construct(Something $something) {
         $this->something = $something;
      }
      public function run() {
         /** ... **/
      }
   }
   $pool = new Pool(8, \MyWorker::class, [new Something()]);
   $pool->submit(new MyWork());
   usleep(1000);
   $pool->collect(function($work){
      return $work->isComplete();
   });
   var_dump($pool);
?>