Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  deprecate forking processes
  add missing annotation
  • Loading branch information
Baptouuuu committed Sep 10, 2023
2 parents eb9ba0b + 41f20c7 commit 32a9f99
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 2 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 3.8.0 - 2023-09-10

### Deprecated

- `Innmind\OperatingSystem\CurrentProcess::fork()`
- `Innmind\OperatingSystem\CurrentProcess::children()`
- `Innmind\OperatingSystem\CurrentProcess\Children`
- `Innmind\OperatingSystem\CurrentProcess\Child`
- `Innmind\OperatingSystem\CurrentProcess\ForkFailed`

## 3.7.0 - 2023-02-25

### Added
Expand Down
2 changes: 2 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public function withEnvironmentPath(EnvironmentPath $path): self
}

/**
* @psalm-mutation-free
*
* @param positive-int $max
*/
public function limitHttpConcurrencyTo(int $max): self
Expand Down
8 changes: 8 additions & 0 deletions src/CurrentProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,17 @@ interface CurrentProcess
public function id(): Pid;

/**
* @deprecated This method will be removed in the next major version
* @psalm-suppress DeprecatedClass
*
* @return Either<ForkFailed|Child, SideEffect> SideEffect represent the child side
*/
public function fork(): Either;

/**
* @deprecated This method will be removed in the next major version
* @psalm-suppress DeprecatedClass
*/
public function children(): Children;
public function signals(): Signals;
public function halt(Period $period): void;
Expand Down
3 changes: 3 additions & 0 deletions src/CurrentProcess/Child.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
ExitCode,
};

/**
* @deprecated This Class will be removed in the next major version
*/
final class Child
{
private Pid $pid;
Expand Down
4 changes: 4 additions & 0 deletions src/CurrentProcess/Children.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
Maybe,
};

/**
* @deprecated This Class will be removed in the next major version
* @psalm-suppress DeprecatedClass
*/
final class Children
{
/** @var Map<int<2, max>, Child> */
Expand Down
1 change: 1 addition & 0 deletions src/CurrentProcess/ForkFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Innmind\OperatingSystem\CurrentProcess;

/**
* @deprecated This class will be removed in the next major version
* @psalm-immutable
*/
final class ForkFailed
Expand Down
21 changes: 19 additions & 2 deletions src/CurrentProcess/Generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@
final class Generic implements CurrentProcess
{
private Halt $halt;
/** @var Set<Child> */
/**
* @psalm-suppress DeprecatedClass
* @var Set<Child>
*/
private Set $children;
private ?Handler $signalsHandler = null;
private ?Signals\Wrapper $signals = null;

private function __construct(Halt $halt)
{
$this->halt = $halt;
/** @var Set<Child> */
/**
* @psalm-suppress DeprecatedClass
* @var Set<Child>
*/
$this->children = Set::of();
}

Expand All @@ -45,6 +51,7 @@ public function fork(): Either
{
/**
* @psalm-suppress ArgumentTypeCoercion
* @psalm-suppress DeprecatedClass
* @var Either<ForkFailed|Child, SideEffect>
*/
$result = match ($pid = \pcntl_fork()) {
Expand All @@ -53,6 +60,9 @@ public function fork(): Either
default => Either::left(Child::of(new Pid($pid))),
};

/**
* @psalm-suppress DeprecatedClass
*/
return $result
->map(function($sideEffect) {
$this->children = $this->children->clear();
Expand All @@ -67,8 +77,12 @@ public function fork(): Either
});
}

/**
* @psalm-suppress DeprecatedClass
*/
public function children(): Children
{
/** @psalm-suppress DeprecatedClass */
return Children::of(...$this->children->toList());
}

Expand All @@ -89,6 +103,9 @@ public function memory(): Bytes
return new Bytes(\memory_get_usage());
}

/**
* @psalm-suppress DeprecatedClass
*/
private function register(Child $child): Child
{
$this->children = ($this->children)($child);
Expand Down
8 changes: 8 additions & 0 deletions src/CurrentProcess/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public function fork(): Either
{
$this->logger->debug('Forking process');

/**
* @psalm-suppress DeprecatedMethod
* @psalm-suppress DeprecatedClass
*/
return $this
->process
->fork()
Expand All @@ -58,8 +62,12 @@ public function fork(): Either
});
}

/**
* @psalm-suppress DeprecatedClass
*/
public function children(): Children
{
/** @psalm-suppress DeprecatedMethod */
return $this->process->children();
}

Expand Down

0 comments on commit 32a9f99

Please sign in to comment.