-
-
Notifications
You must be signed in to change notification settings - Fork 393
Expand file tree
/
Copy pathindex.js
More file actions
28 lines (24 loc) · 892 Bytes
/
index.js
File metadata and controls
28 lines (24 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright 2017 - 2026 will Farrell, Luciano Mammino, and Middy contributors.
// SPDX-License-Identifier: MIT
import { isExecutionModeDurable } from "@middy/util";
const defaults = {
runOnBefore: true,
runOnAfter: false,
runOnError: false,
};
const doNotWaitForEmptyEventLoopMiddleware = (opts = {}) => {
const options = { ...defaults, ...opts };
const doNotWaitForEmptyEventLoop = (request) => {
if (isExecutionModeDurable(request.context)) {
request.context.lambdaContext.callbackWaitsForEmptyEventLoop = false;
} else {
request.context.callbackWaitsForEmptyEventLoop = false;
}
};
return {
before: options.runOnBefore ? doNotWaitForEmptyEventLoop : undefined,
after: options.runOnAfter ? doNotWaitForEmptyEventLoop : undefined,
onError: options.runOnError ? doNotWaitForEmptyEventLoop : undefined,
};
};
export default doNotWaitForEmptyEventLoopMiddleware;