Skip to content

Commit

Permalink
Adds middleware for setting callbackWaitsForEmptyEventLoop false
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinBuschmann committed Nov 28, 2023
1 parent 58c686c commit bcfa376
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/doNotWaitForEmptyEventLoop/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { compose, types } from '../core';
import { doNotWaitForEmptyEventLoop } from './index';
import { inject } from '../inject';

let handler;

beforeEach(() => {
handler = compose(
types<{}, any>(),
inject({}),
doNotWaitForEmptyEventLoop(),
)(async () => {});
});

it('should set callbackWaitsForEmptyEventLoop to false', async () => {
const context = {};
await handler({}, context);
expect(context).toEqual({
callbackWaitsForEmptyEventLoop: false
});
});
10 changes: 10 additions & 0 deletions src/doNotWaitForEmptyEventLoop/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Context } from 'aws-lambda';
import { Middleware } from '../core';

export const doNotWaitForEmptyEventLoop =
<T, R>(): Middleware<T, T, R, R> =>
(next) =>
(event, context: Context, ...args) => {
context.callbackWaitsForEmptyEventLoop = false;
return next(event, context, ...args);
};

0 comments on commit bcfa376

Please sign in to comment.