File tree Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -22,11 +22,15 @@ export type RequestContext = {
2222 serverTiming ?: string
2323 routeHandlerRevalidate ?: NetlifyCachedRouteValue [ 'revalidate' ]
2424 /**
25- * Track promise running in the background and need to be waited for
25+ * Track promise running in the background and need to be waited for.
26+ * Uses `context.waitUntil` if available, otherwise stores promises to
27+ * await on.
2628 */
2729 trackBackgroundWork : ( promise : Promise < unknown > ) => void
2830 /**
29- * Promise that need to be executed even if response was already sent
31+ * Promise that need to be executed even if response was already sent.
32+ * If `context.waitUntil` is available this promise will be always resolved
33+ * because background work tracking was offloaded to `context.waitUntil`.
3034 */
3135 backgroundWorkPromise : Promise < unknown >
3236 logger : SystemLogger
Original file line number Diff line number Diff line change @@ -134,8 +134,9 @@ export default async (request: Request) => {
134134 // otherwise Next would never run the callback variant of `next/after`
135135 res . emit ( 'close' )
136136
137- // if waitUntil is not available, we have to keep response stream open until background promises are resolved
138- // to ensure that all background work executes
137+ // We have to keep response stream open until tracked background promises that are don't use `context.waitUntil`
138+ // are resolved. If `context.waitUntil` is available, `requestContext.backgroundWorkPromise` will be empty
139+ // resolved promised and so awaiting it is no-op
139140 await requestContext . backgroundWorkPromise
140141 } ,
141142 } )
You can’t perform that action at this time.
0 commit comments