diff --git a/src/UnwrapReadableStream.php b/src/UnwrapReadableStream.php index 536ac92..a0d256f 100644 --- a/src/UnwrapReadableStream.php +++ b/src/UnwrapReadableStream.php @@ -6,6 +6,7 @@ use InvalidArgumentException; use React\Promise\PromiseInterface; use React\Stream\ReadableStreamInterface; +use React\Stream\ThroughStream; use React\Stream\Util; use React\Stream\WritableStreamInterface; @@ -75,13 +76,17 @@ function (ReadableStreamInterface $stream) use ($out, &$closed) { return $stream; }, function ($e) use ($out, &$closed) { + // Forward exception as error event if not already closed if (!$closed) { $out->emit('error', array($e, $out)); $out->close(); } - // resume() and pause() may attach to this promise, so ensure we actually reject here - throw $e; + // Both resume() and pause() may attach to this promise, so + // return a NOOP stream instance here. + $stream = new ThroughStream(); + $stream->close(); + return $stream; } ); } diff --git a/tests/FirstTest.php b/tests/FirstTest.php index c40e64f..b5be03b 100644 --- a/tests/FirstTest.php +++ b/tests/FirstTest.php @@ -113,17 +113,6 @@ public function testCancelPendingStreamWillReject() $this->expectPromiseReject($promise); } - public function testNoGarbageCollectionCyclesAfterClosingStream() - { - \gc_collect_cycles(); - $stream = new ThroughStream(); - $promise = Stream\first($stream); - - $stream->close(); - - $this->assertSame(0, \gc_collect_cycles()); - } - public function testShouldResolveWithoutCreatingGarbageCyclesAfterDataThenClose() { \gc_collect_cycles();