@@ -23,10 +23,10 @@ discard block |
||
23 | 23 | { |
24 | 24 | } |
25 | 25 | |
26 | -Amp\Loop::run(function () { |
|
26 | +Amp\Loop::run(function() { |
|
27 | 27 | $dispatcher = new SignalDispatcher(); |
28 | 28 | $dispatcher |
29 | - ->register(Ping::class, function (Ping $cmd) { |
|
29 | + ->register(Ping::class, function(Ping $cmd) { |
|
30 | 30 | if ($cmd->times > 0) { |
31 | 31 | $cmd->times--; |
32 | 32 | |
@@ -37,12 +37,12 @@ discard block |
||
37 | 37 | yield Stop::class => new Stop(); |
38 | 38 | } |
39 | 39 | }) |
40 | - ->register(Pong::class, function (Pong $cmd) { |
|
40 | + ->register(Pong::class, function(Pong $cmd) { |
|
41 | 41 | echo 'Pong!' . \PHP_EOL; |
42 | 42 | |
43 | 43 | yield Ping::class => new Ping($cmd->times); |
44 | 44 | }) |
45 | - ->register(Stop::class, function () { |
|
45 | + ->register(Stop::class, function() { |
|
46 | 46 | echo 'Stop!' . \PHP_EOL; |
47 | 47 | }) |
48 | 48 | ; |
@@ -28,10 +28,10 @@ discard block |
||
28 | 28 | } |
29 | 29 | } |
30 | 30 | |
31 | -Amp\Loop::run(function () { |
|
31 | +Amp\Loop::run(function() { |
|
32 | 32 | $dispatcher = new SignalDispatcher(); |
33 | 33 | $dispatcher |
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 | ; |
@@ -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 | $dispatcher = new SignalDispatcher(); |
11 | 11 | $dispatcher |
12 | - ->register('spawn', function (callable $process) { |
|
12 | + ->register('spawn', function(callable $process) { |
|
13 | 13 | static $pid = 1; |
14 | 14 | |
15 | 15 | $gen = $process($pid); |
@@ -18,35 +18,35 @@ discard block |
||
18 | 18 | |
19 | 19 | return $pid++; |
20 | 20 | }) |
21 | - ->register('send', function (int $pid, string $message, ...$arguments) { |
|
21 | + ->register('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 | - ->register('receive', function (int $pid, string $message, callable $handler) use ($dispatcher) { |
|
26 | + ->register('receive', function(int $pid, string $message, callable $handler) use ($dispatcher) { |
|
27 | 27 | $signal = sprintf('%s.%d', $message, $pid); |
28 | 28 | |
29 | 29 | $dispatcher->register($signal, $handler); |
30 | 30 | }) |
31 | 31 | ; |
32 | 32 | |
33 | - $receiver = yield $dispatcher->dispatch('spawn', function (int $pid) { |
|
34 | - yield 'receive' => [$pid, 'ping', function () { |
|
33 | + $receiver = yield $dispatcher->dispatch('spawn', function(int $pid) { |
|
34 | + yield 'receive' => [$pid, 'ping', function() { |
|
35 | 35 | echo 'Ping!' . \PHP_EOL; |
36 | 36 | }]; |
37 | 37 | |
38 | - yield 'receive' => [$pid, 'pong', function () { |
|
38 | + yield 'receive' => [$pid, 'pong', function() { |
|
39 | 39 | echo 'Pong!' . \PHP_EOL; |
40 | 40 | }]; |
41 | 41 | }); |
42 | 42 | |
43 | - $senderOne = $dispatcher->dispatch('spawn', function () use ($receiver) { |
|
43 | + $senderOne = $dispatcher->dispatch('spawn', function() use ($receiver) { |
|
44 | 44 | yield 'send' => [$receiver, 'ping']; |
45 | 45 | yield new Delayed(500); |
46 | 46 | yield 'send' => [$receiver, 'ping']; |
47 | 47 | }); |
48 | 48 | |
49 | - $senderTwo = $dispatcher->dispatch('spawn', function () use ($receiver) { |
|
49 | + $senderTwo = $dispatcher->dispatch('spawn', function() use ($receiver) { |
|
50 | 50 | yield 'send' => [$receiver, 'pong']; |
51 | 51 | yield new Delayed(100); |
52 | 52 | yield 'send' => [$receiver, 'pong']; |
@@ -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 SignalDispatcher(); |
11 | 11 | $dispatcher |
12 | - ->register('emit', function (string $string, int $num, int $delay = 100) { |
|
12 | + ->register('emit', function(string $string, int $num, int $delay = 100) { |
|
13 | 13 | for ($i = 0; $i < $num; $i++) { |
14 | 14 | echo $string; |
15 | 15 |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function __construct(callable $callable) |
26 | 26 | { |
27 | - $this->callable = $callable; |
|
27 | + $this->callable = $callable; |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public static function error(\Exception $error): self |
36 | 36 | { |
37 | - return new self(function () use ($error) { |
|
37 | + return new self(function() use ($error) { |
|
38 | 38 | throw $error; |
39 | 39 | }); |
40 | 40 | } |
@@ -42,7 +42,7 @@ |
||
42 | 42 | public function register(string $signal, callable $handler): self |
43 | 43 | { |
44 | 44 | $this->handlers->register($signal, $handler); |
45 | - $this->processor->intercept($signal, function (...$arguments) use ($signal) { |
|
45 | + $this->processor->intercept($signal, function(...$arguments) use ($signal) { |
|
46 | 46 | return $this->dispatch($signal, ...$arguments); |
47 | 47 | }); |
48 | 48 |
@@ -52,7 +52,7 @@ |
||
52 | 52 | $token = new TaskToken(); |
53 | 53 | $arguments = (new Arguments($arguments))->inject($this->resolver->resolve($callable)); |
54 | 54 | |
55 | - return new Task(new LazyPromise(function () use ($callable, $arguments, $token) { |
|
55 | + return new Task(new LazyPromise(function() use ($callable, $arguments, $token) { |
|
56 | 56 | $result = $callable(...$arguments); |
57 | 57 | |
58 | 58 | return $result instanceof \Generator ? new Coroutine($this->recoil($result, $token)) : $result; |