From c88b026d868bcbc1ae77afcc2e5771125253a1eb Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 23 Aug 2026 15:26:27 +0200 Subject: [PATCH 1/2] deprecate Handler::async() --- CHANGELOG.md | 6 ++++++ src/Handler.php | 1 + 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64e7ba9..58463c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [Unreleased] + +### Deprecated + +- `Innmind\Signals\Handler::async()` + ## 5.1.0 - 2026-08-16 ### Changed diff --git a/src/Handler.php b/src/Handler.php index 2a42664..83f423b 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] From 24edcaf89ac301f37ac65d6987391737dee6a8e9 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 23 Aug 2026 15:33:34 +0200 Subject: [PATCH 2/2] add Handler::asAsync() --- CHANGELOG.md | 4 ++++ src/Handler.php | 18 +++++++++++++++--- src/Handler/Async.php | 13 ++++++++++--- src/Handler/Main.php | 9 +++++++++ 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58463c4..d3cce6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Added + +- Internal `Innmind\Signals\Handler::asAsync()` + ### Deprecated - `Innmind\Signals\Handler::async()` diff --git a/src/Handler.php b/src/Handler.php index 83f423b..8fc0541 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -46,9 +46,7 @@ public static function async( self $signals, ?Interceptor $interceptor = null, ): self { - return new self( - Async::new($signals, $interceptor), - ); + return $signals->asAsync($interceptor); } /** @@ -72,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> */