function run(): Generator
{
while (true) {
echo yield . '.' . PHP_EOL;
}
}
$run = run();
$run->send('tb');
$run->send('zx');
$run->send('tx');
$run->send('zz');
function run(): Generator
{
$i = 0;
while (true) {
sleep(2);
echo (yield $i++) . '.' . PHP_EOL;
}
}
$run = run();
$run->send('tb');
echo '第:' . $run->current() . '次' . PHP_EOL;
$run->send('zx');
echo '第:' . $run->current() . '次' . PHP_EOL;
$run->send('tx');
echo '第:' . $run->current() . '次' . PHP_EOL;
$run->send('zz');
echo '第:' . $run->current() . '次' . PHP_EOL;