Pool::collect() 函數可以收集對已完成任務的引用。
用法
public int Pool::collect([ Callable $collector ] )
Pool::collect() 函數可以允許池收集由可選的給定Collector確定為垃圾的引用。
Pool::collect() 函數可以返回要收集的池中剩餘任務的數量。
示例
<?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);
?>
相關用法
- PHP Pool::construct()用法及代碼示例
- PHP Pool::submitTo()用法及代碼示例
- PHP Pool::submit()用法及代碼示例
- 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 - Pool::collect() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。