Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/UnwrapReadableStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
);
}
Expand Down
11 changes: 0 additions & 11 deletions tests/FirstTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down