Coroutine¶
Coroutines are methods whose execution may be suspended and resumed.
PHP generators a sort of subroutines.
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";
});
});
?>
See also Coroutine in PHP
Related : Generator
Related packages : swow/swow, swlib/saber, amphp/amp