Fiber::start

(PHP 8 >= 8.1.0)

Fiber::startファイバーの実行を開始する

説明

public Fiber::start(mixed ...$args): mixed

ファイバーを構築する際に使われる callable に対して、可変長引数を指定します。

このメソッドをコールした時点で ファイバーが既に開始されている場合、 FiberError がスローされます。

パラメータ

args

ファイバーのコンストラクタに指定する callable を呼び出す際に、 使用する引数。

戻り値

Fiber::suspend() が最初にコールされた際に指定した値を返します。 ファイバーから制御が戻った場合は null を返します。 停止する前に ファイバーが例外をスローする場合、 このメソッドの呼び出しからスローされます。

add a note

User Contributed Notes 1 note

up
0
Astrid
3 years 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
To Top