@@ -28,10 +28,10 @@ discard block |
||
28 | 28 | } |
29 | 29 | } |
30 | 30 | |
31 | -Amp\Loop::run(function () { |
|
31 | +Amp\Loop::run(function() { |
|
32 | 32 | $builder = new DispatcherBuilder; |
33 | 33 | $builder |
34 | - ->register(SimpleCommand::class, function (SimpleCommand $cmd) { |
|
34 | + ->register(SimpleCommand::class, function(SimpleCommand $cmd) { |
|
35 | 35 | yield new Delayed($cmd->delay); // Just do some heavy calculations |
36 | 36 | yield SimpleEvent::class => new SimpleEvent($cmd->num + $cmd->num); |
37 | 37 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | |
41 | 41 | return $cmd->num; |
42 | 42 | }) |
43 | - ->register(SimpleEvent::class, function (SimpleEvent $event) { |
|
43 | + ->register(SimpleEvent::class, function(SimpleEvent $event) { |
|
44 | 44 | echo \sprintf('Signal dispatched with value: %d at %s' . \PHP_EOL, $event->num, \microtime(true)); |
45 | 45 | }) |
46 | 46 | ; |
@@ -22,10 +22,10 @@ discard block |
||
22 | 22 | { |
23 | 23 | } |
24 | 24 | |
25 | -Amp\Loop::run(function () { |
|
25 | +Amp\Loop::run(function() { |
|
26 | 26 | $builder = new DispatcherBuilder; |
27 | 27 | $builder |
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 | ; |
@@ -5,24 +5,24 @@ |
||
5 | 5 | |
6 | 6 | require __DIR__ . '/../vendor/autoload.php'; |
7 | 7 | |
8 | -Amp\Loop::run(function () { |
|
8 | +Amp\Loop::run(function() { |
|
9 | 9 | $builder = new DispatcherBuilder; |
10 | 10 | $builder |
11 | - ->register('print', function ($num) { |
|
11 | + ->register('print', function($num) { |
|
12 | 12 | for ($i = 0; $i < $num; $i++) { |
13 | 13 | echo '-'; |
14 | 14 | |
15 | 15 | yield new Delayed(100); |
16 | 16 | } |
17 | 17 | }) |
18 | - ->register('print', function ($num) { |
|
18 | + ->register('print', function($num) { |
|
19 | 19 | for ($i = 0; $i < $num; $i++) { |
20 | 20 | echo '+'; |
21 | 21 | |
22 | 22 | yield new Delayed(100); |
23 | 23 | } |
24 | 24 | }) |
25 | - ->register('print', function ($num) { |
|
25 | + ->register('print', function($num) { |
|
26 | 26 | for ($i = 0; $i < $num; $i++) { |
27 | 27 | echo '*'; |
28 | 28 |
@@ -6,10 +6,10 @@ discard block |
||
6 | 6 | |
7 | 7 | require __DIR__ . '/../vendor/autoload.php'; |
8 | 8 | |
9 | -Amp\Loop::run(function () { |
|
9 | +Amp\Loop::run(function() { |
|
10 | 10 | $handlers = new HandlerRegistry; |
11 | 11 | $handlers |
12 | - ->add('spawn', function (callable $process) { |
|
12 | + ->add('spawn', function(callable $process) { |
|
13 | 13 | static $pid = 1; |
14 | 14 | |
15 | 15 | $gen = $process($pid); |
@@ -18,12 +18,12 @@ discard block |
||
18 | 18 | |
19 | 19 | return $pid++; |
20 | 20 | }) |
21 | - ->add('send', function (int $pid, string $message, ...$arguments) { |
|
21 | + ->add('send', function(int $pid, string $message, ...$arguments) { |
|
22 | 22 | $signal = sprintf('%s.%d', $message, $pid); |
23 | 23 | |
24 | 24 | return yield $signal => $arguments; |
25 | 25 | }) |
26 | - ->add('receive', function (int $pid, string $message, callable $handler) use ($handlers) { |
|
26 | + ->add('receive', function(int $pid, string $message, callable $handler) use ($handlers) { |
|
27 | 27 | $signal = sprintf('%s.%d', $message, $pid); |
28 | 28 | |
29 | 29 | $handlers->add($signal, $handler); |
@@ -32,23 +32,23 @@ discard block |
||
32 | 32 | |
33 | 33 | $dispatcher = new Dispatcher($handlers); |
34 | 34 | |
35 | - $receiver = yield $dispatcher->dispatch('spawn', function (int $pid) { |
|
36 | - yield 'receive' => [$pid, 'ping', function () { |
|
35 | + $receiver = yield $dispatcher->dispatch('spawn', function(int $pid) { |
|
36 | + yield 'receive' => [$pid, 'ping', function() { |
|
37 | 37 | echo 'Ping!' . \PHP_EOL; |
38 | 38 | }]; |
39 | 39 | |
40 | - yield 'receive' => [$pid, 'pong', function () { |
|
40 | + yield 'receive' => [$pid, 'pong', function() { |
|
41 | 41 | echo 'Pong!' . \PHP_EOL; |
42 | 42 | }]; |
43 | 43 | }); |
44 | 44 | |
45 | - $senderOne = $dispatcher->dispatch('spawn', function () use ($receiver) { |
|
45 | + $senderOne = $dispatcher->dispatch('spawn', function() use ($receiver) { |
|
46 | 46 | yield 'send' => [$receiver, 'ping']; |
47 | 47 | yield new Delayed(500); |
48 | 48 | yield 'send' => [$receiver, 'ping']; |
49 | 49 | }); |
50 | 50 | |
51 | - $senderTwo = $dispatcher->dispatch('spawn', function () use ($receiver) { |
|
51 | + $senderTwo = $dispatcher->dispatch('spawn', function() use ($receiver) { |
|
52 | 52 | yield 'send' => [$receiver, 'pong']; |
53 | 53 | yield new Delayed(100); |
54 | 54 | yield 'send' => [$receiver, 'pong']; |
@@ -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 | $builder = new DispatcherBuilder; |
10 | 10 | $builder |
11 | - ->register('emit', function (string $string, int $num, int $delay = 100) { |
|
11 | + ->register('emit', function(string $string, int $num, int $delay = 100) { |
|
12 | 12 | for ($i = 0; $i < $num; $i++) { |
13 | 13 | echo $string; |
14 | 14 | |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | |
22 | 22 | $dispatcher = $builder->build(); |
23 | 23 | |
24 | - $times = \rand(5, 10); |
|
24 | + $times = \rand(5, 10); |
|
25 | 25 | $actionOne = $dispatcher->dispatch('emit', '-', $times, 100); |
26 | 26 | $actionTwo = $dispatcher->dispatch('emit', '+', $times + \rand(5, 10), 100); |
27 | 27 |
@@ -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\Wrapper; |
14 | 14 | |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
53 | - return function (...$arguments) use ($handler, $resolved) { |
|
53 | + return function(...$arguments) use ($handler, $resolved) { |
|
54 | 54 | return $handler(...array_replace($arguments, $resolved)); |
55 | 55 | }; |
56 | 56 | } |
@@ -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 | |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function get(string $signal): callable |
51 | 51 | { |
52 | - return $this->handlers[$signal] ?? static function () use ($signal) { |
|
52 | + return $this->handlers[$signal] ?? static function() use ($signal) { |
|
53 | 53 | throw new Exception\UnknownSignal($signal); |
54 | 54 | }; |
55 | 55 | } |
@@ -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 | |
@@ -55,11 +55,11 @@ discard block |
||
55 | 55 | $registry = new HandlerRegistry; |
56 | 56 | |
57 | 57 | foreach ($this->handlers as $signal => $handlers) { |
58 | - $handlers = \array_map(function (callable $handler) { |
|
58 | + $handlers = \array_map(function(callable $handler) { |
|
59 | 59 | return $this->factory->create($handler); |
60 | 60 | }, $handlers); |
61 | 61 | |
62 | - $registry->add($signal, static function (...$arguments) use ($handlers) { |
|
62 | + $registry->add($signal, static function(...$arguments) use ($handlers) { |
|
63 | 63 | $promises = []; |
64 | 64 | |
65 | 65 | foreach ($handlers as $handler) { |