Example about Channel
Example:
<?php
declare(ticks=1);
use vennv\vapm\CoroutineGen;
use vennv\vapm\Channel;
$channel = new Channel();
CoroutineGen::runNonBlocking(function() use (&$channel) {
yield from $channel->receiveGen(function ($result) use (&$channel) {
echo "A: $result\n";
});
});
CoroutineGen::runNonBlocking(function() use (&$channel) {
yield from $channel->receiveGen(function ($result) {
echo "B: $result\n";
});
});
CoroutineGen::runNonBlocking(function() use (&$channel) {
for ($i = 0; $i < 10; $i++) {
yield from $channel->sendGen($i);
}
$channel->close(); // You need must close the channel after sending all the messages
});Output:
Another example:
Output:
Last updated