Added multichannels and a simple channel-based bus

This commit is contained in:
2018-04-16 02:52:51 +02:00
parent 00d2bead8e
commit f8b43beaf5
9 changed files with 241 additions and 11 deletions

28
examples/bus.php Normal file
View File

@ -0,0 +1,28 @@
<?php
require_once __DIR__."/../vendor/autoload.php";
use NoccyLabs\Ipc\Interop\Bus\Master;
$master = new Master();
$client1 = $master->createClient();
$client1->addListener(function ($msg) use ($client1) {
printf("channel1: %s\n", json_encode($msg));
$client1->call("/channel2/hello", "channel1")->then(function ($ret) {
printf("channel1: %s\n", $ret);
});
});
$client2 = $master->createClient();
$client2->addListener(function ($msg) {
printf("channel2: %s\n", json_encode($msg));
});
$client2->export("/channel2/hello", function ($name) {
return sprintf("Hello, %s", $name);
});
$client1->send("hello world");
for ($n = 0; $n < 10; $n++) {
sleep(1);
}