Skip to content

Commit dcb9336

Browse files
authored
Merge pull request #9 from Innmind/void-to-attempt
`CurrentProcess::halt()` now returns `Attempt<SideEffect>`
2 parents 7f3771c + 74fa8cf commit dcb9336

7 files changed

Lines changed: 36 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- Requires `innmind/io:~3.2`
1515
- Requires `innmind/immutable:~5.15`
1616
- `Innmind\OperatingSystem\Config::withHttpHeartbeat()` period is now expressed with a `Innmind\TimeContinuum\Period`
17+
- `Innmind\OperatingSystem\CurrentProcess::halt()` now returns `Innmind\Immutable\Attempt<Innmind\Immutable\SideEffect>`
1718

1819
### Fixed
1920

src/CurrentProcess.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@
77
use Innmind\Server\Control\Server\Process\Pid;
88
use Innmind\Server\Status\Server\Memory\Bytes;
99
use Innmind\TimeContinuum\Period;
10+
use Innmind\Immutable\{
11+
Attempt,
12+
SideEffect,
13+
};
1014

1115
interface CurrentProcess
1216
{
1317
public function id(): Pid;
1418
public function signals(): Signals;
15-
public function halt(Period $period): void;
19+
20+
/**
21+
* @return Attempt<SideEffect>
22+
*/
23+
public function halt(Period $period): Attempt;
1624
public function memory(): Bytes;
1725
}

src/CurrentProcess/Generic.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Innmind\TimeContinuum\Period;
1010
use Innmind\TimeWarp\Halt;
1111
use Innmind\Signals\Handler;
12+
use Innmind\Immutable\Attempt;
1213

1314
final class Generic implements CurrentProcess
1415
{
@@ -45,9 +46,9 @@ public function signals(): Signals
4546
}
4647

4748
#[\Override]
48-
public function halt(Period $period): void
49+
public function halt(Period $period): Attempt
4950
{
50-
($this->halt)($period);
51+
return ($this->halt)($period);
5152
}
5253

5354
#[\Override]

src/CurrentProcess/Logger.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Innmind\Server\Control\Server\Process\Pid;
88
use Innmind\Server\Status\Server\Memory\Bytes;
99
use Innmind\TimeContinuum\Period;
10+
use Innmind\Immutable\Attempt;
1011
use Psr\Log\LoggerInterface;
1112

1213
final class Logger implements CurrentProcess
@@ -49,7 +50,7 @@ public function signals(): Signals
4950
}
5051

5152
#[\Override]
52-
public function halt(Period $period): void
53+
public function halt(Period $period): Attempt
5354
{
5455
$this->logger->debug('Halting current process...', ['period' => [
5556
'years' => $period->years(),
@@ -61,7 +62,7 @@ public function halt(Period $period): void
6162
'milliseconds' => $period->milliseconds(),
6263
]]);
6364

64-
$this->process->halt($period);
65+
return $this->process->halt($period);
6566
}
6667

6768
#[\Override]

src/Remote/Resilient.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use Innmind\Immutable\{
2323
Maybe,
2424
Attempt,
25-
SideEffect,
2625
};
2726
use Formal\AccessLayer\Connection;
2827

@@ -68,9 +67,7 @@ public function __construct(
6867
#[\Override]
6968
public function __invoke(Period $period): Attempt
7069
{
71-
$this->process->halt($period);
72-
73-
return Attempt::result(SideEffect::identity());
70+
return $this->process->halt($period);
7471
}
7572
},
7673
);

tests/CurrentProcess/GenericTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Innmind\Server\Status\Server\Memory\Bytes;
1313
use Innmind\TimeContinuum\Period;
1414
use Innmind\TimeWarp\Halt;
15+
use Innmind\Immutable\SideEffect;
1516
use PHPUnit\Framework\TestCase;
1617

1718
class GenericTest extends TestCase
@@ -38,7 +39,12 @@ public function testHalt()
3839
Halt\Usleep::new(),
3940
);
4041

41-
$this->assertNull($process->halt(Period::millisecond(1)));
42+
$this->assertInstanceOf(
43+
SideEffect::class,
44+
$process
45+
->halt(Period::millisecond(1))
46+
->unwrap(),
47+
);
4248
}
4349

4450
public function testSignals()

tests/CurrentProcess/LoggerTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
use Innmind\Server\Control\Server\Process\Pid;
1212
use Innmind\Server\Status\Server\Memory\Bytes;
1313
use Innmind\TimeContinuum\Period;
14+
use Innmind\Immutable\{
15+
Attempt,
16+
SideEffect,
17+
};
1418
use Psr\Log\LoggerInterface;
1519
use PHPUnit\Framework\TestCase;
1620
use Innmind\BlackBox\{
@@ -74,15 +78,21 @@ public function testHalt()
7478
$inner
7579
->expects($this->once())
7680
->method('halt')
77-
->with($period);
81+
->with($period)
82+
->willReturn(Attempt::result(SideEffect::identity()));
7883
$logger = $this->createMock(LoggerInterface::class);
7984
$logger
8085
->expects($this->once())
8186
->method('debug')
8287
->with('Halting current process...');
8388
$process = Logger::psr($inner, $logger);
8489

85-
$this->assertNull($process->halt($period));
90+
$this->assertInstanceOf(
91+
SideEffect::class,
92+
$process
93+
->halt($period)
94+
->unwrap(),
95+
);
8696
}
8797

8898
public function testMemory()

0 commit comments

Comments
 (0)