Fiber::start
(PHP 8 >= 8.1.0)
Fiber::start — 启动 fiber 的执行
参数
-
args
-
该参数用于调用 fiber 构造函数内指定的 callable。
返回值
首次调用 Fiber::suspend() 提供的值;如果 fiber 已返回,则是 null
。
如果 fiber 在挂起前抛出异常,那么会在调用此方法时的位置抛出异常。

User Contributed Notes 1 note
Astrid ¶
6 months ago
Maybe this helps wrapping your had around the start-suspend-resume-return circle:
$fiber = new Fiber(
function($one) {
$two = Fiber::suspend($one);
$three = Fiber::suspend($two);
$four = Fiber::suspend($three);
$five = Fiber::suspend($four);
$six = Fiber::suspend($five);
return $six;
}
);
print $fiber->start(1);
print $fiber->resume(2);
print $fiber->resume(3);
print $fiber->resume(4);
print $fiber->resume(5);
print $fiber->resume(6);
print $fiber->getReturn();
//prints 123456