Added multichannels and a simple channel-based bus
This commit is contained in:
		
							
								
								
									
										28
									
								
								examples/bus.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								examples/bus.php
									
									
									
									
									
										Normal 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);
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user