await flush

This commit is contained in:
Ciro Spaciari
2024-09-06 16:56:42 -07:00
parent 111e320e56
commit dc6c53824e
2 changed files with 6 additions and 3 deletions

View File

@@ -1260,17 +1260,17 @@ function flushFirstWrite(self) {
new Response(
new ReadableStream({
type: "direct",
pull: controller => {
pull: async controller => {
self[controllerSymbol] = controller;
if (firstWrite) {
controller.write(firstWrite);
controller.flush(); // flush the first write
await controller.flush(); // flush the first write
}
firstWrite = undefined;
if (!self[finishedSymbol]) {
const { promise, resolve } = $newPromiseCapability(GlobalPromise);
self[deferredSymbol] = resolve;
return promise;
return await promise;
}
},
}),

View File

@@ -2477,7 +2477,10 @@ it("response body streaming is immediate (#13696)", async () => {
// chunks before real-time streaming started working.
expect(new Date().getTime() - Number.parseInt(decoder.decode(value).trimEnd(), 10)).toBeLessThan(acceptableDelay);
}
// Verify that the correct number of chunks were sent (in case server
// decides to send no chunks at all).
expect(receivedChunks).toEqual(totalChunks);
// Also verify the total size in case some data was lost.
expect(receivedSize).toEqual(totalSize);
} finally {
server.close();