From 74fa8cf1c26c41589c9e7b38bbd4798eddf3af4e Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sat, 17 May 2025 17:48:22 +0200 Subject: [PATCH] CurrentProcess::halt() now returns Attempt --- CHANGELOG.md | 1 + src/CurrentProcess.php | 10 +++++++++- src/CurrentProcess/Generic.php | 5 +++-- src/CurrentProcess/Logger.php | 5 +++-- src/Remote/Resilient.php | 5 +---- tests/CurrentProcess/GenericTest.php | 8 +++++++- tests/CurrentProcess/LoggerTest.php | 14 ++++++++++++-- 7 files changed, 36 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8543533..9dc05cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - Requires `innmind/io:~3.2` - Requires `innmind/immutable:~5.15` - `Innmind\OperatingSystem\Config::withHttpHeartbeat()` period is now expressed with a `Innmind\TimeContinuum\Period` +- `Innmind\OperatingSystem\CurrentProcess::halt()` now returns `Innmind\Immutable\Attempt` ### Fixed diff --git a/src/CurrentProcess.php b/src/CurrentProcess.php index e86b64e..9ec45b6 100644 --- a/src/CurrentProcess.php +++ b/src/CurrentProcess.php @@ -7,11 +7,19 @@ use Innmind\Server\Control\Server\Process\Pid; use Innmind\Server\Status\Server\Memory\Bytes; use Innmind\TimeContinuum\Period; +use Innmind\Immutable\{ + Attempt, + SideEffect, +}; interface CurrentProcess { public function id(): Pid; public function signals(): Signals; - public function halt(Period $period): void; + + /** + * @return Attempt + */ + public function halt(Period $period): Attempt; public function memory(): Bytes; } diff --git a/src/CurrentProcess/Generic.php b/src/CurrentProcess/Generic.php index a39361f..690b237 100644 --- a/src/CurrentProcess/Generic.php +++ b/src/CurrentProcess/Generic.php @@ -9,6 +9,7 @@ use Innmind\TimeContinuum\Period; use Innmind\TimeWarp\Halt; use Innmind\Signals\Handler; +use Innmind\Immutable\Attempt; final class Generic implements CurrentProcess { @@ -45,9 +46,9 @@ public function signals(): Signals } #[\Override] - public function halt(Period $period): void + public function halt(Period $period): Attempt { - ($this->halt)($period); + return ($this->halt)($period); } #[\Override] diff --git a/src/CurrentProcess/Logger.php b/src/CurrentProcess/Logger.php index 569a901..be33607 100644 --- a/src/CurrentProcess/Logger.php +++ b/src/CurrentProcess/Logger.php @@ -7,6 +7,7 @@ use Innmind\Server\Control\Server\Process\Pid; use Innmind\Server\Status\Server\Memory\Bytes; use Innmind\TimeContinuum\Period; +use Innmind\Immutable\Attempt; use Psr\Log\LoggerInterface; final class Logger implements CurrentProcess @@ -49,7 +50,7 @@ public function signals(): Signals } #[\Override] - public function halt(Period $period): void + public function halt(Period $period): Attempt { $this->logger->debug('Halting current process...', ['period' => [ 'years' => $period->years(), @@ -61,7 +62,7 @@ public function halt(Period $period): void 'milliseconds' => $period->milliseconds(), ]]); - $this->process->halt($period); + return $this->process->halt($period); } #[\Override] diff --git a/src/Remote/Resilient.php b/src/Remote/Resilient.php index daf09b8..1515604 100644 --- a/src/Remote/Resilient.php +++ b/src/Remote/Resilient.php @@ -22,7 +22,6 @@ use Innmind\Immutable\{ Maybe, Attempt, - SideEffect, }; use Formal\AccessLayer\Connection; @@ -68,9 +67,7 @@ public function __construct( #[\Override] public function __invoke(Period $period): Attempt { - $this->process->halt($period); - - return Attempt::result(SideEffect::identity()); + return $this->process->halt($period); } }, ); diff --git a/tests/CurrentProcess/GenericTest.php b/tests/CurrentProcess/GenericTest.php index 0c14cd7..2315189 100644 --- a/tests/CurrentProcess/GenericTest.php +++ b/tests/CurrentProcess/GenericTest.php @@ -12,6 +12,7 @@ use Innmind\Server\Status\Server\Memory\Bytes; use Innmind\TimeContinuum\Period; use Innmind\TimeWarp\Halt; +use Innmind\Immutable\SideEffect; use PHPUnit\Framework\TestCase; class GenericTest extends TestCase @@ -38,7 +39,12 @@ public function testHalt() Halt\Usleep::new(), ); - $this->assertNull($process->halt(Period::millisecond(1))); + $this->assertInstanceOf( + SideEffect::class, + $process + ->halt(Period::millisecond(1)) + ->unwrap(), + ); } public function testSignals() diff --git a/tests/CurrentProcess/LoggerTest.php b/tests/CurrentProcess/LoggerTest.php index f8cec43..50ed108 100644 --- a/tests/CurrentProcess/LoggerTest.php +++ b/tests/CurrentProcess/LoggerTest.php @@ -11,6 +11,10 @@ use Innmind\Server\Control\Server\Process\Pid; use Innmind\Server\Status\Server\Memory\Bytes; use Innmind\TimeContinuum\Period; +use Innmind\Immutable\{ + Attempt, + SideEffect, +}; use Psr\Log\LoggerInterface; use PHPUnit\Framework\TestCase; use Innmind\BlackBox\{ @@ -74,7 +78,8 @@ public function testHalt() $inner ->expects($this->once()) ->method('halt') - ->with($period); + ->with($period) + ->willReturn(Attempt::result(SideEffect::identity())); $logger = $this->createMock(LoggerInterface::class); $logger ->expects($this->once()) @@ -82,7 +87,12 @@ public function testHalt() ->with('Halting current process...'); $process = Logger::psr($inner, $logger); - $this->assertNull($process->halt($period)); + $this->assertInstanceOf( + SideEffect::class, + $process + ->halt($period) + ->unwrap(), + ); } public function testMemory()