mirror of
https://github.com/oven-sh/bun
synced 2026-02-16 22:01:47 +00:00
still fails sometimes
This commit is contained in:
@@ -1255,7 +1255,8 @@ function flushFirstWrite(self) {
|
||||
let firstWrite = self[firstWriteSymbol];
|
||||
// at this point, the user did not call end and we have not flushed the first write
|
||||
// we need to flush it now and behave like chunked encoding
|
||||
|
||||
const { promise: controllerPromise, resolve: resolveController } = $newPromiseCapability(GlobalPromise);
|
||||
self[controllerSymbol] = controllerPromise;
|
||||
self._reply(
|
||||
new Response(
|
||||
new ReadableStream({
|
||||
@@ -1264,6 +1265,8 @@ function flushFirstWrite(self) {
|
||||
self[controllerSymbol] = controller;
|
||||
if (firstWrite) controller.write(firstWrite);
|
||||
firstWrite = undefined;
|
||||
resolveController(controller);
|
||||
|
||||
if (!self[finishedSymbol]) {
|
||||
const { promise, resolve } = $newPromiseCapability(GlobalPromise);
|
||||
self[deferredSymbol] = resolve;
|
||||
@@ -1286,8 +1289,7 @@ ServerResponse.prototype._write = function (chunk, encoding, callback) {
|
||||
|
||||
// we still wanna to flush if the user await some time before writing again
|
||||
// keeping the first write is a good performance optimization
|
||||
// process.nextTick(flushFirstWrite, this);
|
||||
// flushFirstWrite(this);
|
||||
setTimeout(flushFirstWrite, 1, this);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1315,10 +1317,16 @@ ServerResponse.prototype._writev = function (chunks, callback) {
|
||||
|
||||
function ensureReadableStreamController(run) {
|
||||
const thisController = this[controllerSymbol];
|
||||
if (thisController) return run(thisController);
|
||||
if (thisController) {
|
||||
if (thisController.then) {
|
||||
return thisController.then(run);
|
||||
}
|
||||
return run(thisController);
|
||||
}
|
||||
this.headersSent = true;
|
||||
let firstWrite = this[firstWriteSymbol];
|
||||
this[controllerSymbol] = undefined;
|
||||
const { promise: controllerPromise, resolve: resolveController } = $newPromiseCapability(GlobalPromise);
|
||||
this[controllerSymbol] = controllerPromise;
|
||||
this._reply(
|
||||
new Response(
|
||||
new ReadableStream({
|
||||
@@ -1328,6 +1336,8 @@ function ensureReadableStreamController(run) {
|
||||
if (firstWrite) controller.write(firstWrite);
|
||||
firstWrite = undefined;
|
||||
run(controller);
|
||||
resolveController(controller);
|
||||
|
||||
if (!this[finishedSymbol]) {
|
||||
const { promise, resolve } = $newPromiseCapability(GlobalPromise);
|
||||
this[deferredSymbol] = resolve;
|
||||
|
||||
Reference in New Issue
Block a user