<?php
// 下面的示例显示了如何在子线程中使用 Channel::open() 获取通道名称。
使用 parallel\{Channel, Runtime};
$fnThread = static function () {
$channel = Channel::open('channel_name');
$message = $channel->recv();
echo "- 收到消息:$message\n";
返回 'bye';
};
$channel = Channel::make('channel_name', 1);
// 主线程
$runtime = new Runtime();
$future = $runtime->run($fnThread, [$channel]);
echo "发送消息\n";
$channel->send('hello future!');
sleep(1);
echo "关闭通道\n";
$channel->close();
echo "future 说:".$future->value();
echo PHP_EOL;