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