Skip to content
Open
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
36 changes: 36 additions & 0 deletions src/ValueObject/ChildProcessTimeoutException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Symplify\EasyParallel\ValueObject;

use Exception;

class ChildProcessTimeoutException extends Exception
{
/**
* @var mixed[]
*/
private array $context = [];

/**
* @param mixed[] $context
*/
public function __construct(
string $message = '',
array $context = [],
int $code = 0,
?Throwable $previous = null
) {
parent::__construct($message, $code, $previous);
$this->context = $context;
}

/**
* @return mixed[]
*/
public function getContext(): array
{
return $this->context;
}
}
5 changes: 2 additions & 3 deletions src/ValueObject/ParallelProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Clue\React\NDJson\Decoder;
use Clue\React\NDJson\Encoder;
use Exception;
use React\ChildProcess\Process;
use React\EventLoop\LoopInterface;
use React\EventLoop\TimerInterface;
Expand Down Expand Up @@ -98,11 +97,11 @@ public function request(array $data): void
{
$this->cancelTimer();
$this->encoder->write($data);
$this->timer = $this->loop->addTimer($this->timetoutInSeconds, function (): void {
$this->timer = $this->loop->addTimer($this->timetoutInSeconds, function () use ($data): void {
$onError = $this->onError;

$errorMessage = sprintf('Child process timed out after %d seconds', $this->timetoutInSeconds);
$onError(new Exception($errorMessage));
$onError(new ChildProcessTimeoutException($errorMessage, $data));
});
}

Expand Down