Skip to content

Commit b7475f2

Browse files
author
Anton Shabovta
committed
Task to Action rename
1 parent 3bedb1e commit b7475f2

File tree

11 files changed

+46
-77
lines changed

11 files changed

+46
-77
lines changed

examples/cancel.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
;
1919

2020
try {
21-
$task = $dispatcher->dispatch('endless', '.');
21+
$action = $dispatcher->dispatch('endless', '.');
2222

23-
Amp\Loop::delay(500, function () use ($task) {
24-
$task->cancel();
23+
Amp\Loop::delay(500, function () use ($action) {
24+
$action->cancel();
2525
});
2626

27-
yield $task;
27+
yield $action;
2828
} catch (Exception $exception) {
2929
exit(\PHP_EOL . $exception->getMessage());
3030
}

examples/concurent.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
;
2121

2222
$times = \rand(5, 10);
23-
$taskOne = $dispatcher->dispatch('emit', '-', $times, 100);
24-
$taskTwo = $dispatcher->dispatch('emit', '+', $times + \rand(5, 10), 100);
23+
$actionOne = $dispatcher->dispatch('emit', '-', $times, 100);
24+
$actionTwo = $dispatcher->dispatch('emit', '+', $times + \rand(5, 10), 100);
2525

26-
[$resultOne, $resultTwo] = yield [$taskOne, $taskTwo];
26+
[$resultOne, $resultTwo] = yield [$actionOne, $actionTwo];
2727

2828
echo \PHP_EOL;
29-
echo \sprintf('Task one done %d times.' . \PHP_EOL, $resultOne);
30-
echo \sprintf('Task two done %d times.' . \PHP_EOL, $resultTwo);
29+
echo \sprintf('Action one done %d times.' . \PHP_EOL, $resultOne);
30+
echo \sprintf('Action two done %d times.' . \PHP_EOL, $resultTwo);
3131
});

examples/emit.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ public function __construct(int $num, int $delay = 100)
4444
})
4545
;
4646

47-
$task = $dispatcher->dispatch(new SimpleCommand(10));
48-
$data = yield $task;
47+
$data = yield $dispatcher->dispatch(new SimpleCommand(10));
4948

50-
echo \sprintf('Task resolved with value: %d at %s' . \PHP_EOL, $data, \microtime(true));
49+
echo \sprintf('Action resolved with value: %d at %s' . \PHP_EOL, $data, \microtime(true));
5150
});

examples/pool.php

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/Contract/Dispatcher.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@
1616

1717
interface Dispatcher
1818
{
19-
/**
20-
* @param string $signal
21-
* @param callable $handler
22-
*
23-
* @return self
24-
*/
25-
public function register(string $signal, callable $handler): self;
26-
2719
/**
2820
* @param mixed $signal
2921
* @param mixed ...$arguments

src/Dispatcher.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ public function __construct(Kernel $kernel = null)
3333
}
3434

3535
/**
36-
* {@inheritdoc}
36+
* @param string $signal
37+
* @param callable $handler
38+
*
39+
* @return self
3740
*/
38-
public function register(string $signal, callable $handler): Contract\Dispatcher
41+
public function register(string $signal, callable $handler): self
3942
{
4043
$this->handlers[$signal] = $handler;
4144

tests/ActionTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
class ActionTest extends EnsignTest
2121
{
2222
/**
23-
* Test that Task can be canceled
23+
* Test that Action can be canceled
2424
*
2525
* @test
2626
* @expectedException \PHPinnacle\Ensign\Exception\ActionCanceled
@@ -29,15 +29,15 @@ public function cancel()
2929
{
3030
self::loop(function () {
3131
$id = UUID::random();
32-
$task = new Action($id, new Success(), new Token($id));
33-
$task->cancel();
32+
$action = new Action($id, new Success(), new Token($id));
33+
$action->cancel();
3434

35-
yield $task;
35+
yield $action;
3636
});
3737
}
3838

3939
/**
40-
* Test that Task throw exception when timeout reached
40+
* Test that Action throw exception when timeout reached
4141
*
4242
* @test
4343
* @expectedException \PHPinnacle\Ensign\Exception\ActionTimeout
@@ -46,26 +46,26 @@ public function timeout()
4646
{
4747
self::loop(function () {
4848
$id = UUID::random();
49-
$task = new Action($id, new Delayed(100, true), new Token($id));
50-
$task->timeout(10);
49+
$action = new Action($id, new Delayed(100, true), new Token($id));
50+
$action->timeout(10);
5151

52-
yield $task;
52+
yield $action;
5353
});
5454
}
5555

5656
/**
57-
* Test that Task can has timeout
57+
* Test that Action can has timeout
5858
*
5959
* @test
6060
*/
6161
public function fast()
6262
{
6363
self::loop(function () {
6464
$id = UUID::random();
65-
$task = new Action($id, new Success(true), new Token($id));
66-
$task->timeout(100);
65+
$action = new Action($id, new Success(true), new Token($id));
66+
$action->timeout(100);
6767

68-
self::assertTrue(yield $task);
68+
self::assertTrue(yield $action);
6969
});
7070
}
7171
}

tests/DispatcherTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ public function dispatchSignals()
3030
return strtolower($text);
3131
});
3232

33-
self::assertTask($upperTask = $dispatcher->dispatch('upper', 'test'));
34-
self::assertTask($lowerTask = $dispatcher->dispatch('lower', 'TEST'));
33+
self::assertAction($upperAction = $dispatcher->dispatch('upper', 'test'));
34+
self::assertAction($lowerAction = $dispatcher->dispatch('lower', 'TEST'));
3535

36-
self::assertEquals('TEST', yield $upperTask);
37-
self::assertEquals('test', yield $lowerTask);
36+
self::assertEquals('TEST', yield $upperAction);
37+
self::assertEquals('test', yield $lowerAction);
3838
});
3939
}
4040

@@ -51,8 +51,8 @@ public function dispatchObject()
5151
return strtoupper($event->data);
5252
});
5353

54-
self::assertTask($task = $dispatcher->dispatch(new Stub\SimpleEvent('test')));
55-
self::assertEquals('TEST', yield $task);
54+
self::assertAction($action = $dispatcher->dispatch(new Stub\SimpleEvent('test')));
55+
self::assertEquals('TEST', yield $action);
5656
});
5757
}
5858

@@ -84,8 +84,8 @@ public function dispatchSignalFromCoroutine()
8484
self::assertEquals(4, $event->data);
8585
});
8686

87-
self::assertTask($task = $dispatcher->dispatch('coroutine', 3));
88-
self::assertEquals(6, yield $task);
87+
self::assertAction($action = $dispatcher->dispatch('coroutine', 3));
88+
self::assertEquals(6, yield $action);
8989
});
9090
}
9191

@@ -100,7 +100,7 @@ public function dispatchUnknownSignal()
100100
self::loop(function () {
101101
$dispatcher = new Dispatcher();
102102

103-
self::assertTask($failure = $dispatcher->dispatch('unknown'));
103+
self::assertAction($failure = $dispatcher->dispatch('unknown'));
104104

105105
yield $failure;
106106
});

tests/EnsignTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static function assertPromise($value): void
4242
*
4343
* @return void
4444
*/
45-
public static function assertTask($value): void
45+
public static function assertAction($value): void
4646
{
4747
self::assertInstanceOf(Action::class, $value);
4848
}

tests/FunctionsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public function dispatchSignal()
2424
return strtoupper($text);
2525
});
2626

27-
self::assertTask($upperTask = ensign_dispatch('upper', 'test'));
28-
self::assertEquals('TEST', yield $upperTask);
27+
self::assertAction($upperAction = ensign_dispatch('upper', 'test'));
28+
self::assertEquals('TEST', yield $upperAction);
2929
});
3030
}
3131

0 commit comments

Comments
 (0)