@@ -22,10 +22,10 @@ discard block |
||
| 22 | 22 | { |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | -Amp\Loop::run(function () { |
|
| 25 | +Amp\Loop::run(function() { |
|
| 26 | 26 | $dispatcher = new Dispatcher(); |
| 27 | 27 | $dispatcher |
| 28 | - ->register(Ping::class, function (Ping $cmd) { |
|
| 28 | + ->register(Ping::class, function(Ping $cmd) { |
|
| 29 | 29 | if ($cmd->times > 0) { |
| 30 | 30 | $cmd->times--; |
| 31 | 31 | |
@@ -36,12 +36,12 @@ discard block |
||
| 36 | 36 | yield new Stop(); |
| 37 | 37 | } |
| 38 | 38 | }) |
| 39 | - ->register(Pong::class, function (Pong $cmd) { |
|
| 39 | + ->register(Pong::class, function(Pong $cmd) { |
|
| 40 | 40 | echo 'Pong!' . \PHP_EOL; |
| 41 | 41 | |
| 42 | 42 | yield new Ping($cmd->times); |
| 43 | 43 | }) |
| 44 | - ->register(Stop::class, function () { |
|
| 44 | + ->register(Stop::class, function() { |
|
| 45 | 45 | echo 'Stop!' . \PHP_EOL; |
| 46 | 46 | }) |
| 47 | 47 | ; |
@@ -39,32 +39,32 @@ |
||
| 39 | 39 | { |
| 40 | 40 | $listeners = $this->listeners[$message->signal] ?? []; |
| 41 | 41 | |
| 42 | - yield \array_map(function ($listener) use ($message) { |
|
| 42 | + yield \array_map(function($listener) use ($message) { |
|
| 43 | 43 | return $this->processor->execute($listener, $message->arguments); |
| 44 | 44 | }, $listeners); |
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | -Amp\Loop::run(function () { |
|
| 48 | +Amp\Loop::run(function() { |
|
| 49 | 49 | $processor = new Processor(); |
| 50 | 50 | |
| 51 | 51 | $publisher = new Publisher($processor); |
| 52 | 52 | $publisher |
| 53 | - ->listen('print', function ($num) { |
|
| 53 | + ->listen('print', function($num) { |
|
| 54 | 54 | for ($i = 0; $i < $num; $i++) { |
| 55 | 55 | echo '-'; |
| 56 | 56 | |
| 57 | 57 | yield new Delayed(100); |
| 58 | 58 | } |
| 59 | 59 | }) |
| 60 | - ->listen('print', function ($num) { |
|
| 60 | + ->listen('print', function($num) { |
|
| 61 | 61 | for ($i = 0; $i < $num; $i++) { |
| 62 | 62 | echo '+'; |
| 63 | 63 | |
| 64 | 64 | yield new Delayed(100); |
| 65 | 65 | } |
| 66 | 66 | }) |
| 67 | - ->listen('print', function ($num) { |
|
| 67 | + ->listen('print', function($num) { |
|
| 68 | 68 | for ($i = 0; $i < $num; $i++) { |
| 69 | 69 | echo '*'; |
| 70 | 70 | |
@@ -5,10 +5,10 @@ discard block |
||
| 5 | 5 | |
| 6 | 6 | require __DIR__ . '/../vendor/autoload.php'; |
| 7 | 7 | |
| 8 | -Amp\Loop::run(function () { |
|
| 8 | +Amp\Loop::run(function() { |
|
| 9 | 9 | $dispatcher = new Dispatcher(); |
| 10 | 10 | $dispatcher |
| 11 | - ->register('spawn', function (callable $process) { |
|
| 11 | + ->register('spawn', function(callable $process) { |
|
| 12 | 12 | static $pid = 1; |
| 13 | 13 | |
| 14 | 14 | $gen = $process($pid); |
@@ -17,35 +17,35 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | return $pid++; |
| 19 | 19 | }) |
| 20 | - ->register('send', function (int $pid, string $message, ...$arguments) { |
|
| 20 | + ->register('send', function(int $pid, string $message, ...$arguments) { |
|
| 21 | 21 | $signal = sprintf('%s.%d', $message, $pid); |
| 22 | 22 | |
| 23 | 23 | return yield $signal => $arguments; |
| 24 | 24 | }) |
| 25 | - ->register('receive', function (int $pid, string $message, callable $handler) use ($dispatcher) { |
|
| 25 | + ->register('receive', function(int $pid, string $message, callable $handler) use ($dispatcher) { |
|
| 26 | 26 | $signal = sprintf('%s.%d', $message, $pid); |
| 27 | 27 | |
| 28 | 28 | $dispatcher->register($signal, $handler); |
| 29 | 29 | }) |
| 30 | 30 | ; |
| 31 | 31 | |
| 32 | - $receiver = yield $dispatcher->dispatch('spawn', function (int $pid) { |
|
| 33 | - yield 'receive' => [$pid, 'ping', function () { |
|
| 32 | + $receiver = yield $dispatcher->dispatch('spawn', function(int $pid) { |
|
| 33 | + yield 'receive' => [$pid, 'ping', function() { |
|
| 34 | 34 | echo 'Ping!' . \PHP_EOL; |
| 35 | 35 | }]; |
| 36 | 36 | |
| 37 | - yield 'receive' => [$pid, 'pong', function () { |
|
| 37 | + yield 'receive' => [$pid, 'pong', function() { |
|
| 38 | 38 | echo 'Pong!' . \PHP_EOL; |
| 39 | 39 | }]; |
| 40 | 40 | }); |
| 41 | 41 | |
| 42 | - $senderOne = $dispatcher->dispatch('spawn', function () use ($receiver) { |
|
| 42 | + $senderOne = $dispatcher->dispatch('spawn', function() use ($receiver) { |
|
| 43 | 43 | yield 'send' => [$receiver, 'ping']; |
| 44 | 44 | yield new Delayed(500); |
| 45 | 45 | yield 'send' => [$receiver, 'ping']; |
| 46 | 46 | }); |
| 47 | 47 | |
| 48 | - $senderTwo = $dispatcher->dispatch('spawn', function () use ($receiver) { |
|
| 48 | + $senderTwo = $dispatcher->dispatch('spawn', function() use ($receiver) { |
|
| 49 | 49 | yield 'send' => [$receiver, 'pong']; |
| 50 | 50 | yield new Delayed(100); |
| 51 | 51 | yield 'send' => [$receiver, 'pong']; |
@@ -27,10 +27,10 @@ discard block |
||
| 27 | 27 | } |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | -Amp\Loop::run(function () { |
|
| 30 | +Amp\Loop::run(function() { |
|
| 31 | 31 | $dispatcher = new Dispatcher(); |
| 32 | 32 | $dispatcher |
| 33 | - ->register(SimpleCommand::class, function (SimpleCommand $cmd) { |
|
| 33 | + ->register(SimpleCommand::class, function(SimpleCommand $cmd) { |
|
| 34 | 34 | yield new Delayed($cmd->delay); // Just do some heavy calculations |
| 35 | 35 | yield SimpleEvent::class => new SimpleEvent($cmd->num + $cmd->num); |
| 36 | 36 | |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | return $cmd->num; |
| 41 | 41 | }) |
| 42 | - ->register(SimpleEvent::class, function (SimpleEvent $event) { |
|
| 42 | + ->register(SimpleEvent::class, function(SimpleEvent $event) { |
|
| 43 | 43 | echo \sprintf('Signal dispatched with value: %d at %s' . \PHP_EOL, $event->num, \microtime(true)); |
| 44 | 44 | }) |
| 45 | 45 | ; |
@@ -6,10 +6,10 @@ |
||
| 6 | 6 | |
| 7 | 7 | require __DIR__ . '/../vendor/autoload.php'; |
| 8 | 8 | |
| 9 | -Amp\Loop::run(function () { |
|
| 9 | +Amp\Loop::run(function() { |
|
| 10 | 10 | $dispatcher = new Dispatcher(); |
| 11 | 11 | $dispatcher |
| 12 | - ->register('endless', function (string $sign) { |
|
| 12 | + ->register('endless', function(string $sign) { |
|
| 13 | 13 | while (true) { |
| 14 | 14 | yield new Delayed(100); |
| 15 | 15 | |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * file that was distributed with this source code. |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -declare(strict_types = 1); |
|
| 11 | +declare(strict_types=1); |
|
| 12 | 12 | |
| 13 | 13 | namespace PHPinnacle\Ensign; |
| 14 | 14 | |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | { |
| 43 | 43 | $this->handlers[$signal] = $handler; |
| 44 | 44 | |
| 45 | - $this->processor->interrupt($signal, function (...$arguments) use ($signal) { |
|
| 45 | + $this->processor->interrupt($signal, function(...$arguments) use ($signal) { |
|
| 46 | 46 | return $this->dispatch($signal, ...$arguments); |
| 47 | 47 | }); |
| 48 | 48 | |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | $signal = \get_class($signal); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - $handler = $this->handlers[$signal] ?? function () use ($signal) { |
|
| 63 | + $handler = $this->handlers[$signal] ?? function() use ($signal) { |
|
| 64 | 64 | throw new Exception\UnknownSignal($signal); |
| 65 | 65 | }; |
| 66 | 66 | |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * file that was distributed with this source code. |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -declare(strict_types = 1); |
|
| 11 | +declare(strict_types=1); |
|
| 12 | 12 | |
| 13 | 13 | namespace PHPinnacle\Ensign; |
| 14 | 14 | |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | $id = UUID::random(); |
| 45 | 45 | $token = new Token($id); |
| 46 | 46 | |
| 47 | - return new Task($id, new LazyPromise(function () use ($handler, $arguments, $token) { |
|
| 47 | + return new Task($id, new LazyPromise(function() use ($handler, $arguments, $token) { |
|
| 48 | 48 | return $this->adapt($handler(...$arguments), $token); |
| 49 | 49 | }), $token); |
| 50 | 50 | } |