pthreads Worker::collect
(PECL pthreads >= 3.0.0)
Worker::collect — 완료된 작업에 대한 참조 수집
설명
public Worker::collect(Callable $collector
= ?): int
작업자가 선택적으로 제공된 수집기에 의해 가비지라고 결정된 참조를 수집할 수 있도록 합니다.
매개변수
collector
- 작업을 수집할 수 있는지 여부에 대한 부울 값을 반환하는 호출 가능 수집기입니다. 드문 경우에만 맞춤형 수집기를 사용해야 합니다.
반환 값
수집할 작업자 스택의 나머지 작업 수입니다.
Examples
예제 #1 Worker::collect()
의 기본 예
<?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();
위의 예는 다음을 출력합니다.
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