mirror of
https://github.com/danog/parallel.git
synced 2024-12-03 10:07:49 +01:00
44 lines
945 B
PHP
44 lines
945 B
PHP
|
<?php
|
||
|
namespace Icicle\Tests\Concurrent\Sync;
|
||
|
|
||
|
use Icicle\Concurrent\Sync\Channel;
|
||
|
use Icicle\Loop;
|
||
|
|
||
|
class ChannelTest extends \PHPUnit_Framework_TestCase
|
||
|
{
|
||
|
public function testCreate()
|
||
|
{
|
||
|
list($a, $b) = Channel::create();
|
||
|
|
||
|
$this->assertInstanceOf(Channel::class, $a);
|
||
|
$this->assertInstanceOf(Channel::class, $b);
|
||
|
}
|
||
|
|
||
|
public function testClose()
|
||
|
{
|
||
|
list($a, $b) = Channel::create();
|
||
|
|
||
|
// Close $a. $b should close on next read...
|
||
|
$a->close();
|
||
|
$b->receive();
|
||
|
|
||
|
Loop\run();
|
||
|
|
||
|
$this->assertFalse($a->isOpen());
|
||
|
$this->assertFalse($b->isOpen());
|
||
|
}
|
||
|
|
||
|
public function testSendReceive()
|
||
|
{
|
||
|
list($a, $b) = Channel::create();
|
||
|
|
||
|
$a->send('hello')->then(function () use ($b) {
|
||
|
return $b->receive();
|
||
|
})->done(function ($data) {
|
||
|
$this->assertEquals('hello', $data);
|
||
|
});
|
||
|
|
||
|
Loop\run();
|
||
|
}
|
||
|
}
|