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:
parent
582578c092
commit
cb15de11ff
@ -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();
|
||||||
|
Loading…
Reference in New Issue
Block a user