Coroutine

Coroutines are methods whose execution may be suspended and resumed.

PHP generators are a sort of coroutines.

swoole, openswoole and fibers extensions offer coroutines.

<?php

    // Example from OpenSwoole (https://openswoole.com/docs/modules/swoole-coroutine)
    Co\run(function()
    {
        go(function()
        {
            Co::sleep(1);
            echo "Done 1\n";
        });

        go(function()
        {
            Co::sleep(1);
            echo "Done 2\n";
        });
    });

?>

Documentation

See also Coroutine in PHP.

Related : Generator, Blocking Wait, Stealth Generator

Related packages : swow/swow, swlib/saber, amphp/amp