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
16 changes: 8 additions & 8 deletions examples/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use Amp\Delayed;
use PHPinnacle\Ensign\Dispatcher;
use PHPinnacle\Ensign\Kernel;
use PHPinnacle\Ensign\Processor;

require __DIR__ . '/../vendor/autoload.php';

Expand All @@ -20,12 +20,12 @@ public function __construct(string $signal, ...$arguments)

class Publisher
{
private $kernel;
private $processor;
private $listeners = [];

public function __construct(Kernel $kernel)
public function __construct(Processor $processor)
{
$this->kernel = $kernel;
$this->processor = $processor;
}

public function listen(string $signal, callable $listener): self
Expand All @@ -38,16 +38,16 @@ public function listen(string $signal, callable $listener): self
public function __invoke(Publish $message)
{
$actions = \array_map(function ($listener) use ($message) {
return $this->kernel->execute($listener, $message->arguments);
return $this->processor->execute($listener, $message->arguments);
}, $this->listeners[$message->signal] ?? []);

yield $actions;
}
}

Amp\Loop::run(function () {
$kernel = new Kernel();
$publisher = new Publisher($kernel);
$processor = new Processor();
$publisher = new Publisher($processor);
$publisher
->listen('print', function ($num) {
for ($i = 0; $i < $num; $i++) {
Expand All @@ -72,7 +72,7 @@ public function __invoke(Publish $message)
})
;

$dispatcher = new Dispatcher($kernel);
$dispatcher = new Dispatcher($processor);
$dispatcher
->register(Publish::class, $publisher)
;
Expand Down
8 changes: 4 additions & 4 deletions examples/parallel.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

use PHPinnacle\Ensign\Dispatcher;
use PHPinnacle\Ensign\Kernel;
use PHPinnacle\Ensign\Processor;
use PHPinnacle\Ensign\Executor;

require __DIR__ . '/../vendor/autoload.php';

Expand All @@ -12,8 +12,8 @@
}

Amp\Loop::run(function () {
$processor = new Processor\ParallelProcessor();
$dispatcher = new Dispatcher(new Kernel($processor));
$executor = new Executor\ParallelExecutor();
$dispatcher = new Dispatcher(new Processor($executor));
$dispatcher->register('load', function ($url) {
echo "Start getting: {$url}" . \PHP_EOL;

Expand All @@ -27,5 +27,5 @@
$actionThree = $dispatcher->dispatch('load', 'https://amphp.org');

yield [$actionOne, $actionTwo, $actionThree];
yield $processor->shutdown();
yield $executor->shutdown();
});
14 changes: 7 additions & 7 deletions src/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
final class Dispatcher
{
/**
* @var Kernel
* @var Processor
*/
private $kernel;
private $processor;

/**
* @var callable[]
*/
private $handlers = [];

/**
* @param Kernel $kernel
* @param Processor $processor
*/
public function __construct(Kernel $kernel = null)
public function __construct(Processor $processor = null)
{
$this->kernel = $kernel ?: new Kernel();
$this->processor = $processor ?: new Processor();
}

/**
Expand All @@ -42,7 +42,7 @@ public function register(string $signal, callable $handler): self
{
$this->handlers[$signal] = $handler;

$this->kernel->interrupt($signal, function (...$arguments) use ($signal) {
$this->processor->interrupt($signal, function (...$arguments) use ($signal) {
return $this->dispatch($signal, ...$arguments);
});

Expand All @@ -64,6 +64,6 @@ public function dispatch($signal, ...$arguments): Action
throw new Exception\UnknownSignal($signal);
};

return $this->kernel->execute($handler, $arguments);
return $this->processor->execute($handler, $arguments);
}
}
14 changes: 7 additions & 7 deletions src/Exception/ActionTimeout.php → src/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

declare(strict_types = 1);

namespace PHPinnacle\Ensign\Exception;
namespace PHPinnacle\Ensign;

final class ActionTimeout extends EnsignException
interface Executor
{
/**
* @param string $id
* @param callable $handler
* @param array $arguments
*
* @return mixed
*/
public function __construct(string $id)
{
parent::__construct(sprintf('Action "%s" timed out.', $id));
}
public function execute(callable $handler, array $arguments);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

declare(strict_types = 1);

namespace PHPinnacle\Ensign\Processor;
namespace PHPinnacle\Ensign\Executor;

use Amp\Parallel\Worker\DefaultPool;
use Amp\Parallel\Worker\Pool;
use Amp\ParallelFunctions;
use Amp\Promise;
use PHPinnacle\Ensign\Processor;
use PHPinnacle\Ensign\Executor;

final class ParallelProcessor implements Processor
final class ParallelExecutor implements Executor
{
/**
* @var Pool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

declare(strict_types = 1);

namespace PHPinnacle\Ensign\Processor;
namespace PHPinnacle\Ensign\Executor;

use PHPinnacle\Ensign\Processor;
use PHPinnacle\Ensign\Executor;

final class SimpleProcessor implements Processor
final class SimpleExecutor implements Executor
{
/**
* {@inheritdoc}
Expand Down
141 changes: 0 additions & 141 deletions src/Kernel.php

This file was deleted.

Loading