Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## [Unreleased]

### Added

- Internal `Innmind\Signals\Handler::asAsync()`

### Deprecated

- `Innmind\Signals\Handler::async()`

## 5.1.0 - 2026-08-16

### Changed
Expand Down
19 changes: 16 additions & 3 deletions src/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,15 @@ public static function main(): self
* instruct the fiber to terminate.
*
* @internal
* @deprecated
* @psalm-mutation-free
*/
#[\NoDiscard]
public static function async(
self $signals,
?Interceptor $interceptor = null,
): self {
return new self(
Async::new($signals, $interceptor),
);
return $signals->asAsync($interceptor);
}

/**
Expand All @@ -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));
}
}
13 changes: 10 additions & 3 deletions src/Handler/Async.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
namespace Innmind\Signals\Handler;

use Innmind\Signals\{
Handler,
Signal,
Info,
Async\Interceptor,
Expand All @@ -23,7 +22,7 @@ final class Async
* @psalm-mutation-free
*/
private function __construct(
private Handler $parent,
private self|Main $parent,
private ?Interceptor $interceptor,
) {
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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 ?
}
}
9 changes: 9 additions & 0 deletions src/Handler/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Innmind\Signals\{
Signal,
Info,
Async\Interceptor,
};
use Innmind\Immutable\{
Sequence,
Expand Down Expand Up @@ -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<Sequence<callable(Signal, Info): void>>
*/
Expand Down
Loading