Skip to content

Commit 4840945

Browse files
authored
Merge pull request #37 from clue-labs/unhandled-rejections
Update unwrapped stream to avoid unhandled promise rejections
2 parents a2e9560 + 5fffe2b commit 4840945

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

src/UnwrapReadableStream.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use InvalidArgumentException;
77
use React\Promise\PromiseInterface;
88
use React\Stream\ReadableStreamInterface;
9+
use React\Stream\ThroughStream;
910
use React\Stream\Util;
1011
use React\Stream\WritableStreamInterface;
1112

@@ -75,13 +76,17 @@ function (ReadableStreamInterface $stream) use ($out, &$closed) {
7576
return $stream;
7677
},
7778
function ($e) use ($out, &$closed) {
79+
// Forward exception as error event if not already closed
7880
if (!$closed) {
7981
$out->emit('error', array($e, $out));
8082
$out->close();
8183
}
8284

83-
// resume() and pause() may attach to this promise, so ensure we actually reject here
84-
throw $e;
85+
// Both resume() and pause() may attach to this promise, so
86+
// return a NOOP stream instance here.
87+
$stream = new ThroughStream();
88+
$stream->close();
89+
return $stream;
8590
}
8691
);
8792
}

tests/FirstTest.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,6 @@ public function testCancelPendingStreamWillReject()
113113
$this->expectPromiseReject($promise);
114114
}
115115

116-
public function testNoGarbageCollectionCyclesAfterClosingStream()
117-
{
118-
\gc_collect_cycles();
119-
$stream = new ThroughStream();
120-
$promise = Stream\first($stream);
121-
122-
$stream->close();
123-
124-
$this->assertSame(0, \gc_collect_cycles());
125-
}
126-
127116
public function testShouldResolveWithoutCreatingGarbageCyclesAfterDataThenClose()
128117
{
129118
\gc_collect_cycles();

0 commit comments

Comments
 (0)