Skip to content

Commit

Permalink
streams: use nextTick on close
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelGSS committed Nov 21, 2021
1 parent 5c5608e commit c4f0058
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions lib/internal/webstreams/readablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -1403,32 +1403,36 @@ function readableStreamTee(stream, cloneForBranch2) {
reading = true;
const readRequest = {
[kChunk](value) {
reading = false;
const value1 = value;
let value2 = value;
if (!canceled2 && cloneForBranch2) {
// Structured Clone
value2 = deserialize(serialize(value2));
}
if (!canceled1) {
readableStreamDefaultControllerEnqueue(
branch1[kState].controller,
value1);
}
if (!canceled2) {
readableStreamDefaultControllerEnqueue(
branch2[kState].controller,
value2);
}
queueMicrotask(() => {
reading = false;
const value1 = value;
let value2 = value;
if (!canceled2 && cloneForBranch2) {
// Structured Clone
value2 = deserialize(serialize(value2));
}
if (!canceled1) {
readableStreamDefaultControllerEnqueue(
branch1[kState].controller,
value1);
}
if (!canceled2) {
readableStreamDefaultControllerEnqueue(
branch2[kState].controller,
value2);
}
});
},
[kClose]() {
reading = false;
if (!canceled1)
readableStreamDefaultControllerClose(branch1[kState].controller);
if (!canceled2)
readableStreamDefaultControllerClose(branch2[kState].controller);
if (!canceled1 || !canceled2)
cancelPromise.resolve();
process.nextTick(() => {
reading = false;
if (!canceled1)
readableStreamDefaultControllerClose(branch1[kState].controller);
if (!canceled2)
readableStreamDefaultControllerClose(branch2[kState].controller);
if (!canceled1 || !canceled2)
cancelPromise.resolve();
})
},
[kError]() {
reading = false;
Expand Down

0 comments on commit c4f0058

Please sign in to comment.