Fiber::start

(PHP 8 >= 8.1.0)

Fiber::startInicia execução de uma Fibra

Descrição

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

Uma lista variável de argumentos a ser fornecida para o callable usado na construção da Fiber.

Se a Fiber já tiver sido iniciada quando este método for chamado, uma exceção FiberError será disparada.

Parâmetros

args

Os argumentos que serão utilizados na chamada ao callable fornecido ao construtor da Fiber.

Valor Retornado

O valor fornecido à primeira chamada a Fiber::suspend() ou null se a Fiber retornar. Se a Fiber disparar uma exceção antes de ser suspensa, ela será disparada a partir da chamada a este método.

add a note

User Contributed Notes 1 note

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