Skip to content

Commit f701685

Browse files
committed
fix: only create signal when needed
1 parent b732ab8 commit f701685

File tree

3 files changed

+36
-141
lines changed

3 files changed

+36
-141
lines changed

package-lock.json

Lines changed: 30 additions & 140 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"lint-staged": "^15.0.0",
7070
"prettier": "^3.0.0",
7171
"sinon": "^17.0.0",
72+
"speedscope": "1.16.0",
7273
"tinybench": "^2.5.1",
7374
"ts-standard": "^12.0.0",
7475
"tsd": "^0.29.0"

packages/core/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ const middy = (lambdaHandler = defaultLambdaHandler, plugin = {}) => {
129129
return middy
130130
}
131131

132+
// shared AbortController, because it's slow
133+
let handlerAbort = new AbortController()
132134
const runRequest = async (
133135
request,
134136
beforeMiddlewares,
@@ -151,7 +153,9 @@ const runRequest = async (
151153

152154
// Can't manually abort and timeout with same AbortSignal
153155
// https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static
154-
const handlerAbort = new AbortController()
156+
if (handlerAbort.signal.aborted) {
157+
handlerAbort = new AbortController()
158+
}
155159
const promises = [
156160
lambdaHandler(request.event, request.context, {
157161
signal: handlerAbort.signal

0 commit comments

Comments
 (0)