Skip to content

Commit

Permalink
Disable callbackWaitsForEmptyEventLoop for promise based handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
RafalSumislawski committed Jul 11, 2024
1 parent 641bce8 commit 95698b7
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions nodejs/packages/cx-wrapper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,35 @@ export const handler = (event: any, context: Context, callback: Callback) => {
maybePromise.then(
value => {
diag.debug(`maybePromise succeeded`);
context.callbackWaitsForEmptyEventLoop = false;
callback(null, value);
diag.debug(`callback called`);
},
(err: Error | string) => {
diag.debug(`maybePromise failed`);
callback(err, null);
diag.debug(`callback called`);
(err: Error | string | null | undefined) => {
if (err === undefined || err === null) {
diag.debug(`maybePromise failed with no error`);
context.callbackWaitsForEmptyEventLoop = false;
callback('handled', null);
diag.debug(`callback called`);
} else {
diag.debug(`maybePromise failed`);
context.callbackWaitsForEmptyEventLoop = false;
callback(err, null);
diag.debug(`callback called`);
}
}
);
}
} catch (err: any) {
diag.debug(`handler failed synchronously`);
context.callbackWaitsForEmptyEventLoop = false;
callback(err, null);
diag.debug(`callback called`);
}
},
(err: Error | string) => {
diag.debug(`loading function failed`);
context.callbackWaitsForEmptyEventLoop = false;
callback(err, null)
diag.debug(`callback called`);
}
Expand Down

0 comments on commit 95698b7

Please sign in to comment.