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
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
*.webp binary
*.bmp binary
*.ttf binary
*.blp binary
*.db2 binary

# Ignoring files for distribution archieves
.github/ export-ignore
etc/ci/ export-ignore
etc/dev-app/ export-ignore
etc/qa/ export-ignore
examples/ export-ignore
tests/ export-ignore
Expand Down
12 changes: 8 additions & 4 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"github>WyriHaximus/renovate-config:php-package"
]
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"github>WyriHaximus/renovate-config:php-package"
],
"constraints": {
"php": "8.4.x",
"composer": "2.x"
}
}
115 changes: 85 additions & 30 deletions Makefile

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"require-dev": {
"react-parallel/pool-tests": "^5.1.0 || ^6.0.0",
"wyrihaximus/async-test-utilities": "^12.2.0",
"wyrihaximus/makefiles": "^0.7.16"
"wyrihaximus/makefiles": "^0.10.6"
},
"autoload": {
"psr-4": {
Expand Down
18 changes: 9 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion etc/qa/infection.json5
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"timeout": 120,
"source": {
"directories": [
"src"
"../../src"
]
},
"logs": {
Expand Down
1 change: 1 addition & 0 deletions etc/qa/phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<arg value="np" /> <!-- n = ignore warnings, p = show progress -->

<file>../../etc</file>
<file>../../examples</file>
<file>../../src</file>
<file>../../tests</file>

Expand Down
8 changes: 5 additions & 3 deletions examples/echo.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<?php

declare(strict_types=1);

use React\EventLoop\Factory;
use ReactParallel\EventLoop\EventLoopBridge;
use ReactParallel\Pool\Infinite\Direct;

require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';

$loop = Factory::create();
$loop = Factory::create();
$infinite = new Direct($loop, new EventLoopBridge($loop), 1);
$infinite->run(function () {
$infinite->run(static function () {
sleep(1);

return 'Hoi!';
})->then(function (string $message) use ($infinite, $loop) {
})->then(static function (string $message) use ($infinite, $loop): void {
echo $message, PHP_EOL;
$infinite->close();
$loop->stop();
Expand Down
10 changes: 6 additions & 4 deletions examples/exception.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use React\EventLoop\Factory;
use ReactParallel\EventLoop\EventLoopBridge;
use ReactParallel\Pool\Infinite\Direct;
Expand All @@ -10,16 +12,16 @@

$infinite = new Direct($loop, new EventLoopBridge($loop), 1);

$infinite->run(function () {
$infinite->run(static function () {
throw new RuntimeException('Whoops I did it again!');

return 'We shouldn\'t reach this!';
})->always(function () use ($infinite, $loop) {
})->always(static function () use ($infinite, $loop): void {
$infinite->close();
$loop->stop();
})->then(function (string $oops) {
})->then(static function (string $oops): void {
echo $oops, PHP_EOL;
}, function (Throwable $error) {
}, static function (Throwable $error): void {
echo $error, PHP_EOL;
})->done();

Expand Down
19 changes: 11 additions & 8 deletions examples/json.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php

declare(strict_types=1);

use React\EventLoop\Factory;
use ReactParallel\EventLoop\EventLoopBridge;
use function React\Promise\all;
use ReactParallel\Pool\Infinite\Direct;

use function React\Promise\all;

$json = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'large.json');

require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
Expand All @@ -14,30 +16,31 @@

$infinite = new Direct($loop, new EventLoopBridge($loop), 1);

$promises = [];
$signalHandler = function () use ($infinite, $loop) {
$promises = [];
$signalHandler = static function () use ($infinite, $loop): void {
$loop->stop();
$infinite->close();
};

$tick = function () use (&$promises, $infinite, $loop, $signalHandler, $json, &$tick) {
$tick = static function () use (&$promises, $infinite, $loop, $signalHandler, $json, &$tick): void {
if (count($promises) < 1000) {
$promises[] = $infinite->run(function($json) {
$promises[] = $infinite->run(static function ($json) {
$json = json_decode($json, true);

return md5(json_encode($json));
}, [$json]);
$loop->futureTick($tick);

return;
}

all($promises)->then(function ($v) {
all($promises)->then(static function ($v): void {
var_export($v);
})->always(function () use ($infinite, $loop, $signalHandler) {
})->always(static function () use ($infinite, $loop, $signalHandler): void {
$infinite->close();
$loop->removeSignal(SIGINT, $signalHandler);
$loop->stop();
})->done();

};
$loop->futureTick($tick);

Expand Down
13 changes: 8 additions & 5 deletions examples/sleep.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use React\EventLoop\Factory;
use ReactParallel\EventLoop\EventLoopBridge;
use ReactParallel\Pool\Infinite\Direct;
Expand All @@ -13,27 +15,28 @@

$infinite = new Direct($loop, new EventLoopBridge($loop), 0.1);

$timer = $loop->addPeriodicTimer(1, function () use ($infinite) {
$timer = $loop->addPeriodicTimer(1, static function () use ($infinite): void {
var_export(iteratorOrArrayToArray($infinite->info()));
});

$promises = [];
foreach (range(0, 250) as $i) {
$promises[] = $infinite->run(function($sleep) {
$promises[] = $infinite->run(static function ($sleep) {
sleep($sleep);

return $sleep;
}, [random_int(1, 13)])->then(function (int $sleep) use ($i) {
}, [random_int(1, 13)])->then(static function (int $sleep) use ($i) {
echo $i, '; ', $sleep, PHP_EOL;

return $sleep;
});
}

$signalHandler = function () use ($infinite, $loop) {
$signalHandler = static function () use ($infinite, $loop): void {
$loop->stop();
$infinite->close();
};
all($promises)->then(function ($v) use ($infinite, $loop, $signalHandler, $timer) {
all($promises)->then(static function ($v) use ($infinite, $loop, $signalHandler, $timer): void {
$infinite->close();
$loop->removeSignal(SIGINT, $signalHandler);
$loop->cancelTimer($timer);
Expand Down
8 changes: 5 additions & 3 deletions examples/versions.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use Composer\InstalledVersions;
use React\EventLoop\Factory;
use ReactParallel\EventLoop\EventLoopBridge;
Expand All @@ -11,13 +13,13 @@

$finite = new Direct($loop, new EventLoopBridge($loop), 0.1);

$loop->addTimer(1, function () use ($finite, $loop) {
$loop->addTimer(1, static function () use ($finite, $loop): void {
$finite->kill();
$loop->stop();
});
$finite->run(function (): array {
$finite->run(static function (): array {
return array_merge(...array_map(static fn (string $package): array => [$package => InstalledVersions::getPrettyVersion($package)], InstalledVersions::getInstalledPackages()));
})->then(function (array $versions): void {
})->then(static function (array $versions): void {
var_export($versions);
});

Expand Down
3 changes: 1 addition & 2 deletions tests/DirectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ final class DirectTest extends AbstractPoolTest
{
use PoolInfoTestTrait;

/** @phpstan-ignore-next-line */
private function poolFactory(): PoolInfoInterface
protected function poolFactory(): PoolInfoInterface
{
return new Direct()->withMetrics(Metrics::create(MetricsFactory::create()));
}
Expand Down
Loading