当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


PHP Worker::collect()用法及代码示例



Worker::collect() 函数可以收集对已完成任务的引用。

用法

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

Worker::collect() 函数可以允许工作人员收集由可选给定的Collector确定为垃圾的引用。

Worker::collect() 函数可以返回要收集的 worker 堆栈上剩余任务的数量。

示例

<?php
   $worker = new Worker();
   echo "There are currently {$worker->collect()} tasks on the stack to be collected\n";

   for($i = 0; $i < 15; ++$i) {
      $worker->stack(new class extends Threaded {});
   }
   echo "There are {$worker->collect()} tasks remaining on the stack to be collected\n";

   $worker->start();
   while($worker->collect()); // blocks until all tasks have finished executing
   echo "There are now {$worker->collect()} tasks on the stack to be collected\n";
   $worker->shutdown();
?>

相关用法


注:本文由纯净天空筛选整理自 PHP - Worker::collect() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。