File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -396,6 +396,12 @@ export async function invokeFunction(
396396 process . env [ key ] = environment [ key ]
397397 } )
398398
399+ let resolveInvocation , rejectInvocation
400+ const invocationPromise = new Promise ( ( resolve , reject ) => {
401+ resolveInvocation = resolve
402+ rejectInvocation = reject
403+ } )
404+
399405 const response = ( await execute ( {
400406 event : {
401407 headers : headers || { } ,
@@ -405,8 +411,20 @@ export async function invokeFunction(
405411 } ,
406412 lambdaFunc : { handler } ,
407413 timeoutMs : 4_000 ,
414+ onInvocationEnd : ( error ) => {
415+ // lambda-local resolve promise return from execute when response is closed
416+ // but we should wait for tracked background work to finish
417+ // before resolving the promise to allow background work to finish
418+ if ( error ) {
419+ rejectInvocation ( error )
420+ } else {
421+ resolveInvocation ( )
422+ }
423+ } ,
408424 } ) ) as LambdaResponse
409425
426+ await invocationPromise
427+
410428 const responseHeaders = Object . entries ( response . multiValueHeaders || { } ) . reduce (
411429 ( prev , [ key , value ] ) => ( {
412430 ...prev ,
You can’t perform that action at this time.
0 commit comments