Skip to content

Commit

Permalink
give access to the OS when building an actor
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptouuuu committed Nov 16, 2024
1 parent e8cec24 commit 3aa7176
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/Factories.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Innmind\Witness;

use Innmind\OperatingSystem\OperatingSystem;
use Innmind\Immutable\{
Maybe,
Map,
Expand All @@ -14,7 +15,7 @@
final class Factories
{
/**
* @param Map<class-string<Actor>, callable(Message, Spawn): Actor> $factories
* @param Map<class-string<Actor>, callable(OperatingSystem, Message, Spawn): Actor> $factories
*/
private function __construct(
private Map $factories,
Expand All @@ -32,6 +33,7 @@ private function __construct(
* @return Maybe<T>
*/
public function __invoke(
OperatingSystem $os,
string $actor,
Message $argument,
Spawn $spawn,
Expand All @@ -41,13 +43,14 @@ public function __invoke(
->factories
->get($actor)
->map(static fn($factory) => $factory(
$os,
$argument,
$spawn,
));
}

/**
* @param Map<class-string<Actor>, callable(Message, Spawn): Actor> $factories
* @param Map<class-string<Actor>, callable(OperatingSystem, Message, Spawn): Actor> $factories
*/
public static function of(Map $factories): self
{
Expand Down
4 changes: 2 additions & 2 deletions src/Genesis.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
final class Genesis
{
/**
* @param Map<class-string<Actor>, callable(Message, Spawn): Actor> $factories
* @param Map<class-string<Actor>, callable(OperatingSystem, Message, Spawn): Actor> $factories
* @param Sequence<class-string<Message>> $messages
*/
private function __construct(
Expand Down Expand Up @@ -53,7 +53,7 @@ public static function of(
* @template T of Actor<I, A>
*
* @param class-string<T> $class
* @param callable(A, Spawn): T $factory
* @param callable(OperatingSystem, A, Spawn): T $factory
*/
public function actor(string $class, callable $factory): self
{
Expand Down
1 change: 1 addition & 0 deletions src/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function __invoke(OperatingSystem $os): void
->keep(Instance::of(Init::class))
->flatMap(
fn($init) => ($this->factories)(
$os,
$init->actor(),
$init->argument(),
$spawn,
Expand Down

0 comments on commit 3aa7176

Please sign in to comment.