-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds middleware for setting callbackWaitsForEmptyEventLoop false
- Loading branch information
1 parent
58c686c
commit bcfa376
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |