File tree 1 file changed +18
-0
lines changed
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(
396
396
process . env [ key ] = environment [ key ]
397
397
} )
398
398
399
+ let resolveInvocation , rejectInvocation
400
+ const invocationPromise = new Promise ( ( resolve , reject ) => {
401
+ resolveInvocation = resolve
402
+ rejectInvocation = reject
403
+ } )
404
+
399
405
const response = ( await execute ( {
400
406
event : {
401
407
headers : headers || { } ,
@@ -405,8 +411,20 @@ export async function invokeFunction(
405
411
} ,
406
412
lambdaFunc : { handler } ,
407
413
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
+ } ,
408
424
} ) ) as LambdaResponse
409
425
426
+ await invocationPromise
427
+
410
428
const responseHeaders = Object . entries ( response . multiValueHeaders || { } ) . reduce (
411
429
( prev , [ key , value ] ) => ( {
412
430
...prev ,
You can’t perform that action at this time.
0 commit comments