File tree 2 files changed +9
-4
lines changed
2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -22,11 +22,15 @@ export type RequestContext = {
22
22
serverTiming ?: string
23
23
routeHandlerRevalidate ?: NetlifyCachedRouteValue [ 'revalidate' ]
24
24
/**
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.
26
28
*/
27
29
trackBackgroundWork : ( promise : Promise < unknown > ) => void
28
30
/**
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`.
30
34
*/
31
35
backgroundWorkPromise : Promise < unknown >
32
36
logger : SystemLogger
Original file line number Diff line number Diff line change @@ -134,8 +134,9 @@ export default async (request: Request) => {
134
134
// otherwise Next would never run the callback variant of `next/after`
135
135
res . emit ( 'close' )
136
136
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
139
140
await requestContext . backgroundWorkPromise
140
141
} ,
141
142
} )
You can’t perform that action at this time.
0 commit comments