Update README.md, consistent use of spaces instead of tabs, better examples

This commit is contained in:
2020-12-12 13:05:48 +01:00
parent 92bc0ab407
commit db081158d7
30 changed files with 997 additions and 1041 deletions

47
src/Concurrency.php Normal file
View File

@@ -0,0 +1,47 @@
<?php
namespace Toalett\Multiprocessing;
use Toalett\Multiprocessing\Exception\InvalidArgumentException;
class Concurrency
{
private const VALUE_UNLIMITED = -1;
private int $limit;
private function __construct(int $limit)
{
if ($limit === 0 || $limit < self::VALUE_UNLIMITED) {
throw new InvalidArgumentException('-1 or positive integer', $limit);
}
$this->limit = $limit;
}
public static function singleWorker(): self
{
return new self(1);
}
public static function atMost(int $limit): self
{
return new self($limit);
}
public static function unlimited(): self
{
return new self(self::VALUE_UNLIMITED);
}
public function isUnlimited(): bool
{
return $this->limit === self::VALUE_UNLIMITED;
}
public function isReachedBy(int $amount): bool
{
if ($this->isUnlimited()) {
return false;
}
return $amount >= $this->limit;
}
}