1
0
mirror of https://github.com/danog/byte-stream.git synced 2024-11-26 20:04:51 +01:00

Fix Message::read() if stream fails with a pending read

This commit is contained in:
Niklas Keller 2017-10-06 21:40:40 +02:00
parent 0dff1fe859
commit af613a0a77
2 changed files with 30 additions and 0 deletions

View File

@ -103,6 +103,12 @@ class Message implements InputStream, Promise {
if ($error) {
$this->error = $error;
}
if ($this->pendingRead) {
$deferred = $this->pendingRead;
$this->pendingRead = null;
$deferred->fail($error);
}
});
}

View File

@ -143,6 +143,30 @@ class MessageTest extends TestCase {
});
}
public function testFailingStreamWithPendingRead() {
Loop::run(function () {
$exception = new TestException;
$value = "abc";
$emitter = new Emitter;
$stream = new Message(new IteratorStream($emitter->iterate()));
$readPromise = $stream->read();
$emitter->fail($exception);
$callable = $this->createCallback(1);
try {
yield $readPromise;
$this->fail("No exception has been thrown");
} catch (TestException $reason) {
$this->assertSame($exception, $reason);
$callable(); // <-- ensure this point is reached
}
});
}
public function testEmptyStream() {
Loop::run(function () {
$emitter = new Emitter;