diff --git a/CHANGELOG.md b/CHANGELOG.md index 64e7ba9..d3cce6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## [Unreleased] + +### Added + +- Internal `Innmind\Signals\Handler::asAsync()` + +### Deprecated + +- `Innmind\Signals\Handler::async()` + ## 5.1.0 - 2026-08-16 ### Changed diff --git a/src/Handler.php b/src/Handler.php index 2a42664..8fc0541 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -38,6 +38,7 @@ public static function main(): self * instruct the fiber to terminate. * * @internal + * @deprecated * @psalm-mutation-free */ #[\NoDiscard] @@ -45,9 +46,7 @@ public static function async( self $signals, ?Interceptor $interceptor = null, ): self { - return new self( - Async::new($signals, $interceptor), - ); + return $signals->asAsync($interceptor); } /** @@ -71,4 +70,18 @@ public function remove(callable $listener): Attempt { return $this->implementation->remove($listener); } + + /** + * This is intended to build a child handler inside a Fiber. + * The interceptor allows to emulate a signals to send a fake signal to + * instruct the fiber to terminate. + * + * @internal + * @psalm-mutation-free + */ + #[\NoDiscard] + public function asAsync(?Interceptor $interceptor = null): self + { + return new self($this->implementation->asAsync($interceptor)); + } } diff --git a/src/Handler/Async.php b/src/Handler/Async.php index 3939282..0e716a8 100644 --- a/src/Handler/Async.php +++ b/src/Handler/Async.php @@ -4,7 +4,6 @@ namespace Innmind\Signals\Handler; use Innmind\Signals\{ - Handler, Signal, Info, Async\Interceptor, @@ -23,7 +22,7 @@ final class Async * @psalm-mutation-free */ private function __construct( - private Handler $parent, + private self|Main $parent, private ?Interceptor $interceptor, ) { } @@ -32,7 +31,7 @@ private function __construct( * @psalm-pure */ #[\NoDiscard] - public static function new(Handler $parent, ?Interceptor $interceptor): self + public static function new(self|Main $parent, ?Interceptor $interceptor): self { return new self($parent, $interceptor); } @@ -70,4 +69,12 @@ public function remove(callable $listener): Attempt return $_; }); } + + /** + * @psalm-mutation-free + */ + public function asAsync(?Interceptor $interceptor): self + { + return new self($this, $interceptor); // todo return $this when no interceptor ? + } } diff --git a/src/Handler/Main.php b/src/Handler/Main.php index dcdfb89..a66d5de 100644 --- a/src/Handler/Main.php +++ b/src/Handler/Main.php @@ -6,6 +6,7 @@ use Innmind\Signals\{ Signal, Info, + Async\Interceptor, }; use Innmind\Immutable\{ Sequence, @@ -117,6 +118,14 @@ public function remove(callable $listener): Attempt }); } + /** + * @psalm-mutation-free + */ + public function asAsync(?Interceptor $interceptor): Async + { + return Async::new($this, $interceptor); + } + /** * @return Attempt> */