mirror of
https://github.com/danog/parallel.git
synced 2024-11-26 20:34:40 +01:00
Don't swallow SynchronizationError in ContextException
This commit is contained in:
parent
f2e5224856
commit
f919371aee
@ -269,15 +269,15 @@ final class Parallel implements Context
|
||||
return call(function () {
|
||||
try {
|
||||
$response = yield $this->channel->receive();
|
||||
|
||||
if (!$response instanceof ExitResult) {
|
||||
throw new SynchronizationError('Did not receive an exit result from thread.');
|
||||
}
|
||||
$this->close();
|
||||
} catch (\Throwable $exception) {
|
||||
$this->kill();
|
||||
throw new ContextException("Failed to receive result from thread", 0, $exception);
|
||||
} finally {
|
||||
$this->close();
|
||||
}
|
||||
|
||||
if (!$response instanceof ExitResult) {
|
||||
$this->kill();
|
||||
throw new SynchronizationError('Did not receive an exit result from thread.');
|
||||
}
|
||||
|
||||
return $response->getResult();
|
||||
|
@ -263,9 +263,6 @@ final class Process implements Context
|
||||
return call(function () {
|
||||
try {
|
||||
$data = yield $this->channel->receive();
|
||||
if (!$data instanceof ExitResult) {
|
||||
throw new SynchronizationError("Did not receive an exit result from process");
|
||||
}
|
||||
} catch (\Throwable $exception) {
|
||||
if ($this->isRunning()) {
|
||||
$this->kill();
|
||||
@ -273,6 +270,13 @@ final class Process implements Context
|
||||
throw new ContextException("Failed to receive result from process", 0, $exception);
|
||||
}
|
||||
|
||||
if (!$data instanceof ExitResult) {
|
||||
if ($this->isRunning()) {
|
||||
$this->kill();
|
||||
}
|
||||
throw new SynchronizationError("Did not receive an exit result from process");
|
||||
}
|
||||
|
||||
$this->channel->close();
|
||||
|
||||
$code = yield $this->process->join();
|
||||
|
@ -230,10 +230,6 @@ final class Thread implements Context
|
||||
|
||||
try {
|
||||
$response = yield $this->channel->receive();
|
||||
|
||||
if (!$response instanceof ExitResult) {
|
||||
throw new SynchronizationError('Did not receive an exit result from thread.');
|
||||
}
|
||||
} catch (\Throwable $exception) {
|
||||
$this->kill();
|
||||
throw new ContextException("Failed to receive result from thread", 0, $exception);
|
||||
@ -242,6 +238,11 @@ final class Thread implements Context
|
||||
$this->close();
|
||||
}
|
||||
|
||||
if (!$response instanceof ExitResult) {
|
||||
$this->kill();
|
||||
throw new SynchronizationError('Did not receive an exit result from thread.');
|
||||
}
|
||||
|
||||
return $response->getResult();
|
||||
});
|
||||
}
|
||||
|
@ -269,7 +269,7 @@ class ThreadTest extends TestCase
|
||||
|
||||
/**
|
||||
* @expectedException \Amp\Parallel\Context\ContextException
|
||||
* @expectedExceptionMessage The context stopped responding
|
||||
* @expectedExceptionMessage Failed to receive result
|
||||
*/
|
||||
public function testExitingContextOnJoin()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user