Fiber::start

(PHP 8 >= 8.1.0)

Fiber::start启动 fiber 的执行

说明

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

当构造 fiber 时提供用于 callable 的可变参数列表。

如果调用此方法时 fiber 已经启动,则会抛出 FiberError

参数

args

该参数用于调用 fiber 构造函数内指定的 callable。

返回值

首次调用 Fiber::suspend() 提供的值;如果 fiber 已返回,则是 null。 如果 fiber 在挂起前抛出异常,那么会在调用此方法时的位置抛出异常。

add a note

User Contributed Notes 1 note

up
0
Astrid
2 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