Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public function __construct(LoopInterface $loop)
$this->loop = $loop;
}

public function loop(): LoopInterface
{
return $this->loop;
}

public function eventLoopBridge(): EventLoopBridge
{
if ($this->eventLoopBridge === null) {
Expand Down
25 changes: 10 additions & 15 deletions tests/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,57 +16,53 @@ final class FactoryTest extends AsyncTestCase
*/
public function eventLoopBridge(): void
{
$loop = EventLoopFactory::create();
$factory = new Factory($loop);
$factory = new Factory(EventLoopFactory::create());

$future = run(function (int $a, int $b): int {
return $a * $b;
}, [333, 2]);
assert($future instanceof Future);

self::assertSame(666, $this->await($factory->eventLoopBridge()->await($future), $loop));
self::assertSame(666, $this->await($factory->eventLoopBridge()->await($future), $factory->loop()));
}

/**
* @test
*/
public function streams(): void
{
$loop = EventLoopFactory::create();
$factory = new Factory($loop);
$factory = new Factory(EventLoopFactory::create());

$time = time();
$channel = new Channel(Channel::Infinite);
$channel->send($time);

self::assertSame($time, $this->await($factory->streams()->single($channel), $loop));
self::assertSame($time, $this->await($factory->streams()->single($channel), $factory->loop()));
}

/**
* @test
*/
public function call(): void
{
$loop = EventLoopFactory::create();
$factory = new Factory($loop);
$factory = new Factory(EventLoopFactory::create());

self::assertSame(666, $this->await($factory->call(function (int $a, int $b): int {
return $a * $b;
}, [333, 2]), $loop));
}, [333, 2]), $factory->loop()));
}

/**
* @test
*/
public function infinitePool(): void
{
$loop = EventLoopFactory::create();
$factory = new Factory($loop);
$factory = new Factory(EventLoopFactory::create());

$pool = $factory->infinitePool();
self::assertSame(666, $this->await($pool->run(function (int $a, int $b): int {
return $a * $b;
}, [333, 2]), $loop));
}, [333, 2]), $factory->loop()));
$pool->close();
}

Expand All @@ -75,13 +71,12 @@ public function infinitePool(): void
*/
public function limitedPool(): void
{
$loop = EventLoopFactory::create();
$factory = new Factory($loop);
$factory = new Factory(EventLoopFactory::create());

$pool = $factory->limitedPool(1);
self::assertSame(666, $this->await($pool->run(function (int $a, int $b): int {
return $a * $b;
}, [333, 2]), $loop));
}, [333, 2]), $factory->loop()));
$pool->close();
}
}