Skip to content

Commit

Permalink
switch flowing
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed Sep 27, 2021
1 parent 3852aef commit 3aacb60
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function renderToReadableStream(
options?: Options,
): ReadableStream {
let request;
return new ReadableStream({
const stream = new ReadableStream({
start(controller) {
request = createRequest(
model,
Expand All @@ -37,10 +37,17 @@ function renderToReadableStream(
startWork(request);
},
pull(controller) {
startFlowing(request);
// Pull is called immediately even if the stream is not passed to anything.
// That's buffering too early. We want to start buffering once the stream
// is actually used by something so we can give it the best result possible
// at that point.
if (stream.locked) {
startFlowing(request);
}
},
cancel(reason) {},
});
return stream;
}

export {renderToReadableStream};
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ function pipeToNodeWritable(
webpackMap,
options ? options.onError : undefined,
);
destination.on('drain', createDrainHandler(destination, request));
startWork(request);
startFlowing(request);
destination.on('drain', createDrainHandler(destination, request));
}

export {pipeToNodeWritable};

0 comments on commit 3aacb60

Please sign in to comment.