diff --git a/src/doNotWaitForEmptyEventLoop/index.spec.ts b/src/doNotWaitForEmptyEventLoop/index.spec.ts new file mode 100644 index 0000000..8f14b5b --- /dev/null +++ b/src/doNotWaitForEmptyEventLoop/index.spec.ts @@ -0,0 +1,17 @@ +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, + }); +}); diff --git a/src/doNotWaitForEmptyEventLoop/index.ts b/src/doNotWaitForEmptyEventLoop/index.ts new file mode 100644 index 0000000..b97c6c9 --- /dev/null +++ b/src/doNotWaitForEmptyEventLoop/index.ts @@ -0,0 +1,10 @@ +import { Context } from 'aws-lambda'; +import { Middleware } from '../core'; + +export const doNotWaitForEmptyEventLoop = + (): Middleware => + (next) => + (event, context: Context, ...args) => { + context.callbackWaitsForEmptyEventLoop = false; + return next(event, context, ...args); + };