PHP 8.5.0 Released!

Fiber::start

(PHP 8 >= 8.1.0)

Fiber::startInicia la ejecución de la fibra

Descripción

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

Una lista variádica de argumentos a proporcionar a la función utilizada durante la construcción de la fibra.

Si la fibra ya ha sido iniciada cuando se llama a este método, se emitirá un error FiberError.

Parámetros

args

Los argumentos a utilizar durante la invocación de la función dada al constructor de la fibra.

Valores devueltos

El valor proporcionado a la primera llamada a Fiber::suspend() o null si la fibra retorna. Si la fibra lanza una excepción antes de suspenderse, será emitida durante la llamada a este método.

add a note

User Contributed Notes 1 note

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