Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update unwrapped stream to avoid unhandled promise rejections #37

Merged
merged 1 commit into from
Jul 7, 2023
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.
Jump to
Jump to file
Failed to load files.
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());
}

clue marked this conversation as resolved.
Show resolved Hide resolved
public function testShouldResolveWithoutCreatingGarbageCyclesAfterDataThenClose()
{
\gc_collect_cycles();
Expand Down