1
0
mirror of https://github.com/danog/parallel.git synced 2024-11-30 04:39:01 +01:00

Catch StreamExceptions thrown when reading

try/catch should have been around call to read().
This commit is contained in:
Aaron Piotrowski 2017-12-10 13:54:11 -06:00
parent 582578c092
commit cb15de11ff
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB

View File

@ -58,15 +58,17 @@ class ChannelledStream implements Channel {
public function receive(): Promise { public function receive(): Promise {
return call(function () { return call(function () {
while ($this->received->isEmpty()) { while ($this->received->isEmpty()) {
if (($chunk = yield $this->read->read()) === null) {
throw new ChannelException("The channel closed. Did the context die?");
}
try { try {
$this->parser->push($chunk); $chunk = yield $this->read->read();
} catch (StreamException $exception) { } catch (StreamException $exception) {
throw new ChannelException("Reading from the channel failed. Did the context die?", $exception); throw new ChannelException("Reading from the channel failed. Did the context die?", $exception);
} }
if ($chunk === null) {
throw new ChannelException("The channel closed unexpectedly. Did the context die?");
}
$this->parser->push($chunk);
} }
return $this->received->shift(); return $this->received->shift();