Skip to content

Instantly share code, notes, and snippets.

@iggyvolz
Created December 23, 2019 19:57
Show Gist options
  • Save iggyvolz/21f6349050a45763ab348c62915cb0b5 to your computer and use it in GitHub Desktop.
Save iggyvolz/21f6349050a45763ab348c62915cb0b5 to your computer and use it in GitHub Desktop.
<?php
use \parallel\Runtime;
use \parallel\Channel;
$runtime = new Runtime();
Channel::make("TEST_CHANNEL", 1024);
$future1 = $runtime->run(function(){
$channel = Channel::open("TEST_CHANNEL");
sleep(2);
$channel->send("foo");
sleep(1);
$channel->send("bar");
sleep(1);
});
$future2 = $runtime->run(function(){
$channel = Channel::open("TEST_CHANNEL");
$msg1=$channel->recv();
$msg2=$channel->recv();
return "$msg1, $msg2";
});
echo $future2->value();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment