Implement Unit Tests, add Readme, add examples, stronger implementation

This commit is contained in:
2020-12-11 01:25:38 +01:00
commit ffebc74a7d
19 changed files with 3149 additions and 0 deletions

39
src/ContextBuilder.php Normal file
View File

@@ -0,0 +1,39 @@
<?php
namespace Toalett\Multiprocessing;
use React\EventLoop\Factory;
use React\EventLoop\LoopInterface;
class ContextBuilder
{
private ?LoopInterface $loop = null;
private ?ConcurrencyLimit $limit = null;
public static function create(): self
{
return new self();
}
public function withEventLoop(LoopInterface $loop): self
{
$instance = clone $this;
$instance->loop = $loop;
return $instance;
}
public function withLimit(ConcurrencyLimit $limit): self
{
$instance = clone $this;
$instance->limit = $limit;
return $instance;
}
public function build(): Context
{
return new Context(
$this->loop ?? Factory::create(),
$this->limit ?? ConcurrencyLimit::unlimited()
);
}
}