Skip to content

Commit

Permalink
Base (#1)
Browse files Browse the repository at this point in the history
* React pool

* Tweaks

* Fix closure sending

* Use generator

* Remove PHP 7.x

* Property type

* Create base

* Add pool factory

* Small changes

* Change variable name

* Fix action link

* Update test
  • Loading branch information
jenky authored Jul 8, 2023
1 parent 302da48 commit 57ae16f
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 286 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
matrix:
# os: [ubuntu-latest, windows-latest]
os: [ubuntu-latest]
php: [7.2, 7.3, 7.4, 8.0, 8.1, 8.2]
php: [8.1, 8.2]

name: PHP ${{ matrix.php }} / ${{ matrix.os }}

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ The MIT License (MIT). Please see [License File](LICENSE.md) for more informatio
[link-travis]: https://travis-ci.org/jenky/atlas-pool
[link-scrutinizer]: https://scrutinizer-ci.com/g/jenky/atlas-pool/code-structure
[link-code-quality]: https://scrutinizer-ci.com/g/jenky/atlas-pool
[link-gh-actions]: https://github.com/jenky/jenky/atlas-pool
[link-gh-actions]: https://github.com/jenky/atlas-pool
[link-codecov]: https://codecov.io/gh/jenky/atlas-pool
[link-downloads]: https://packagist.org/packages/jenky/atlas-pool

10 changes: 4 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
}
],
"require": {
"php": "^7.2.5|^8.0"
"php": "^8.1",
"jenky/atlas": "^0.4"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.4",
"guzzlehttp/guzzle": "^7.5",
"jenky/atlas": "1.x-dev",
"jenky/atlas-mock-client": "^1.0",
"friendsofphp/php-cs-fixer": "^3.15",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^8.0|^9.0"
"phpunit/phpunit": "^9.0"
},
"autoload": {
"psr-4": {
Expand Down
127 changes: 0 additions & 127 deletions src/Guzzle/Pool.php

This file was deleted.

31 changes: 0 additions & 31 deletions src/Guzzle/ResolvePromise.php

This file was deleted.

30 changes: 8 additions & 22 deletions src/PoolFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,22 @@

namespace Jenky\Atlas\Pool;

use GuzzleHttp\ClientInterface;
use Jenky\Atlas\Contracts\ConnectorInterface;
use Jenky\Atlas\Pool\Exceptions\UnsupportedException;

final class PoolFactory
{
/**
* Create a new pool instance for given connector.
*
* @throws UnsupportedException
*/
public static function create(ConnectorInterface $connector): PoolInterface
{
$client = $connector->client();

if ($client instanceof ClientInterface) {
return new Guzzle\Pool($connector);
if (class_exists(React\Pool::class)) {
return new React\Pool($connector); //@phpstan-ignore-line
}

throw new UnsupportedException('Pool feature is not supported for current client '.get_class($client));
throw new UnsupportedException('You cannot use the pool feature as the "jenky/atlas-react-pool" package is not installed.');
}

/*
* Get default pool instance.
*
* @return array<class-string, callable>
*/
/* private static function candidates(): array
{
return [
ReactPool::class => fn (): bool => function_exists('React\\Async\\async')
&& function_exists('React\\Async\\await')
&& function_exists('React\\Async\\parallel'),
AmpPool::class => fn (): bool => function_exists('Amp\\async')
&& function_exists('Amp\\Future\awaitAll'),
];
} */
}
13 changes: 9 additions & 4 deletions src/PoolInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@

namespace Jenky\Atlas\Pool;

use Jenky\Atlas\Response;

/**
* @template TReq
* @template TRes
*/
interface PoolInterface
{
/**
* Set the maximum number of requests to send concurrently.
*/
public function concurrent(int $concurrency): PoolInterface;

/**
* Send concurrent requests.
*
* @param iterable $requests
* @return array<array-key, Response>
* @param iterable<TReq> $requests
* @return array<array-key, TRes>
*/
public function send(iterable $requests): array;
}
22 changes: 22 additions & 0 deletions src/PoolTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Jenky\Atlas\Pool;

trait PoolTrait
{
private int $concurrency = 25;

public function concurrent(int $concurrency): PoolInterface
{
if ($concurrency < 1) {
throw new \ValueError('Argument #1 ($concurrency) must be positive, got '.$concurrency);
}

$clone = clone $this;
$clone->concurrency = $concurrency;

return $clone;
}
}
25 changes: 0 additions & 25 deletions tests/AkamaiTileRequest.php

This file was deleted.

26 changes: 26 additions & 0 deletions tests/DummyRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Jenky\Atlas\Pool\Tests;

use Jenky\Atlas\Request;

final class DummyRequest extends Request
{
public function __construct(
private string $uri = 'https://example.com',
private string $method = 'GET'
) {
}

public function method(): string
{
return $this->method;
}

public function endpoint(): string
{
return $this->uri;
}
}
18 changes: 0 additions & 18 deletions tests/EchoConnector.php

This file was deleted.

30 changes: 0 additions & 30 deletions tests/EchoRequest.php

This file was deleted.

Loading

0 comments on commit 57ae16f

Please sign in to comment.