php 8 new fiber class doesn't work as async

Viewed 30

I'm trying the Fiber object in PHP and it's experimenting with loop. If async works, the result should be 1,2,3,4,5 because of the "sleep" function and it shouldn't wait.But result is 5,4,3,2,1

function getClosure(): Closure
{
    return static function (int $item) {
        sleep($item);
        Fiber::suspend($item);
    };
}

$ranges = range(5, 1, -1);
foreach ($ranges as $range) {

    $f = new Fiber(getClosure());
    echo $f->start($range);
}


0 Answers
Related