Unverified Commit 616bcb37 authored by Janka Uryga's avatar Janka Uryga Committed by GitHub

refactor(after): remove unnecessary conditionals (#73447)

These should've been removed in #73190 because we're always creating a
`closeController`.
parent 18e8bfbb
...@@ -289,13 +289,11 @@ export async function adapter( ...@@ -289,13 +289,11 @@ export async function adapter(
} finally { } finally {
// middleware cannot stream, so we can consider the response closed // middleware cannot stream, so we can consider the response closed
// as soon as the handler returns. // as soon as the handler returns.
if (closeController) { // we can delay running it until a bit later --
// we can delay running it until a bit later -- // if it's needed, we'll have a `waitUntil` lock anyway.
// if it's needed, we'll have a `waitUntil` lock anyway. setTimeout(() => {
setTimeout(() => { closeController.dispatchClose()
closeController!.dispatchClose() }, 0)
}, 0)
}
} }
} }
) )
......
...@@ -127,25 +127,21 @@ export class EdgeRouteModuleWrapper { ...@@ -127,25 +127,21 @@ export class EdgeRouteModuleWrapper {
} }
evt.waitUntil(Promise.all(waitUntilPromises)) evt.waitUntil(Promise.all(waitUntilPromises))
if (closeController) { if (!res.body) {
const _closeController = closeController // TS annoyance - "possibly undefined" in callbacks // we can delay running it until a bit later --
// if it's needed, we'll have a `waitUntil` lock anyway.
if (!res.body) { setTimeout(() => closeController.dispatchClose(), 0)
// we can delay running it until a bit later -- } else {
// if it's needed, we'll have a `waitUntil` lock anyway. // NOTE: if this is a streaming response, onClose may be called later,
setTimeout(() => _closeController.dispatchClose(), 0) // so we can't rely on `closeController.listeners` -- it might be 0 at this point.
} else { const trackedBody = trackStreamConsumed(res.body, () =>
// NOTE: if this is a streaming response, onClose may be called later, closeController.dispatchClose()
// so we can't rely on `closeController.listeners` -- it might be 0 at this point. )
const trackedBody = trackStreamConsumed(res.body, () => res = new Response(trackedBody, {
_closeController.dispatchClose() status: res.status,
) statusText: res.statusText,
res = new Response(trackedBody, { headers: res.headers,
status: res.status, })
statusText: res.statusText,
headers: res.headers,
})
}
} }
return res return res
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment