diff --git a/src/ValueObject/ChildProcessTimeoutException.php b/src/ValueObject/ChildProcessTimeoutException.php new file mode 100644 index 0000000..7cacd66 --- /dev/null +++ b/src/ValueObject/ChildProcessTimeoutException.php @@ -0,0 +1,36 @@ +context = $context; + } + + /** + * @return mixed[] + */ + public function getContext(): array + { + return $this->context; + } +} diff --git a/src/ValueObject/ParallelProcess.php b/src/ValueObject/ParallelProcess.php index b7a0362..ae04758 100644 --- a/src/ValueObject/ParallelProcess.php +++ b/src/ValueObject/ParallelProcess.php @@ -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; @@ -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)); }); }