略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Fiber::start

2024-05-18

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 noteadd a note

User Contributed Notes 1 note

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

官方地址:https://www.php.net/manual/en/fiber.start.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3