Skip to content

Commit

Permalink
Merge pull request #73 from vuongxuongminh/synchronous-catch-exceptio…
Browse files Browse the repository at this point in the history
…n-bugfix

Bugfix handling exception in synchronous process
  • Loading branch information
brendt authored Aug 2, 2019
2 parents c46ec31 + f87c335 commit a002e1e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Process/ProcessCallbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public function triggerError()
}
}

abstract protected function resolveErrorOutput(): Throwable;

public function triggerTimeout()
{
foreach ($this->timeoutCallbacks as $callback) {
Expand Down
5 changes: 5 additions & 0 deletions src/Process/SynchronousProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,9 @@ public function getCurrentExecutionTime(): float
{
return $this->executionTime;
}

protected function resolveErrorOutput(): Throwable
{
return $this->getErrorOutput();
}
}
18 changes: 18 additions & 0 deletions tests/ErrorHandlingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,22 @@ public function deep_syntax_errors_are_thrown()

$pool->wait();
}

/** @test */
public function it_can_handle_synchronous_exception()
{
Pool::$forceSynchronous = true;

$pool = Pool::create();

$pool->add(function () {
throw new MyException('test');
})->catch(function (MyException $e) {
$this->assertRegExp('/test/', $e->getMessage());
});

$pool->wait();

Pool::$forceSynchronous = false;
}
}

0 comments on commit a002e1e

Please sign in to comment.