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:
parent
0dff1fe859
commit
af613a0a77
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user