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,15 +289,13 @@ export async function adapter(
} finally {
// middleware cannot stream, so we can consider the response closed
// as soon as the handler returns.
if (closeController) {
// we can delay running it until a bit later --
// if it's needed, we'll have a `waitUntil` lock anyway.
setTimeout(() => {
closeController!.dispatchClose()
closeController.dispatchClose()
}, 0)
}
}
}
)
}
return params.handler(request, event)
......
......@@ -127,18 +127,15 @@ export class EdgeRouteModuleWrapper {
}
evt.waitUntil(Promise.all(waitUntilPromises))
if (closeController) {
const _closeController = closeController // TS annoyance - "possibly undefined" in callbacks
if (!res.body) {
// we can delay running it until a bit later --
// if it's needed, we'll have a `waitUntil` lock anyway.
setTimeout(() => _closeController.dispatchClose(), 0)
setTimeout(() => closeController.dispatchClose(), 0)
} else {
// NOTE: if this is a streaming response, onClose may be called later,
// so we can't rely on `closeController.listeners` -- it might be 0 at this point.
const trackedBody = trackStreamConsumed(res.body, () =>
_closeController.dispatchClose()
closeController.dispatchClose()
)
res = new Response(trackedBody, {
status: res.status,
......@@ -146,7 +143,6 @@ export class EdgeRouteModuleWrapper {
headers: res.headers,
})
}
}
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