Skip to content

Commit

Permalink
Merge pull request #4 from reactphp-parallel/add-example
Browse files Browse the repository at this point in the history
Add Example
  • Loading branch information
WyriHaximus committed Sep 7, 2020
2 parents 36892e4 + de77da6 commit 580ff70
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -16,6 +16,7 @@
},
"require-dev": {
"monolog/monolog": "^2.1",
"psr/log": "^1.1",
"wyrihaximus/async-test-utilities": "^2.3",
"yuloh/container": "^1.0"
},
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

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

34 changes: 34 additions & 0 deletions examples/logger.php
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Psr\Log\LoggerInterface;
use React\EventLoop\Factory;
use ReactParallel\Factory as ParallelFactory;
use ReactParallel\ObjectProxy\Proxy;
use ReactParallel\Psr11ContainerProxy\ContainerProxy;
use Yuloh\Container\Container;

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

$loop = Factory::create();
$parallelFactory = new ParallelFactory($loop);
$container = new Container();
$container->set(LoggerInterface::class, static fn (): LoggerInterface => new Logger('main', [new StreamHandler(STDOUT)]));
$proxy = new ContainerProxy($container, new Proxy($parallelFactory));
$parallelFactory->call(static function (ContainerProxy $proxy, int $time): int {
$container = new Container();
$container->set('logger', static fn (): LoggerInterface => new Logger('child', [new StreamHandler(STDOUT)]));
$containerProxy = $proxy->create($container);
$containerProxy->get('logger')->critical('Time: ' . $time);
$containerProxy->get(LoggerInterface::class)->critical('Time: ' . $time);

return $time;
}, [$proxy, time()])->then(static function (int $time) use ($parallelFactory): void {
echo 'Time: ', $time;
$parallelFactory->lowLevelPool()->kill();
})->done();

$loop->run();
1 change: 1 addition & 0 deletions phpcs.xml.dist
Expand Up @@ -8,6 +8,7 @@

<file>src</file>
<file>tests</file>
<file>examples</file>

<rule ref="WyriHaximus-OSS" />
</ruleset>

0 comments on commit 580ff70

Please sign in to comment.