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 PHPUnit assertIsNotFloat()用法及代碼示例
- PHP disk_total_space()用法及代碼示例
- PHP ReflectionClass getTraitAliases()用法及代碼示例
- PHP hash_hmac()用法及代碼示例
- PHP String wordwrap()用法及代碼示例
- PHP SimpleXMLElement children()用法及代碼示例
- PHP is_file( )用法及代碼示例
- PHP ArrayIterator asort()用法及代碼示例
- PHP IntlCalendar getTimeZone()用法及代碼示例
- PHP SplPriorityQueue isCorrupted()用法及代碼示例
- PHP XMLReader::getParserProperty()用法及代碼示例
- PHP imagegif()用法及代碼示例
- PHP imageresolution()用法及代碼示例
- PHP SplFileInfo getPerms()用法及代碼示例
注:本文由純淨天空篩選整理自 PHP - Worker::collect() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。