PHP 8.1.31 Released!

parallel\Channel::open

(0.9.0)

parallel\Channel::openДоступ

Описание

public parallel\Channel::open(string $name): Channel

Открывает канал с заданным именем

Ошибки

Внимание

Выбрасывает parallel\Channel\Error\Existence, если канал не существует.

Добавить

Примечания пользователей 1 note

up
0
gam6itko
3 years ago
<?php

// example below shows how to get channel by name within child thread with Channel::open()

use parallel\{Channel, Runtime};

$fnThread = static function () {
$channel = Channel::open('channel_name');
$message = $channel->recv();
echo
"- received message: $message\n";

return
'bye';
};

$channel = Channel::make('channel_name', 1);

// main thread
$runtime = new Runtime();
$future = $runtime->run($fnThread, [$channel]);

echo
"sending message\n";
$channel->send('hello future!');
sleep(1);
echo
"closing channel\n";
$channel->close();

echo
"future said: ".$future->value();
echo
PHP_EOL;
To Top