Skip to content

Commit 20cb467

Browse files
Update serve.js to clear the timeout if a function invocation is a success within the timeout.
1 parent 6f470ae commit 20cb467

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Diff for: lib/serve.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,20 @@ function createHandler(dir, static, timeout) {
135135
{ clientContext: buildClientContext(request.headers) || {} },
136136
callback
137137
);
138+
139+
var invocationTimeoutRef = null
140+
138141
Promise.race([
139142
promiseCallback(promise, callback),
140-
setTimeout(function() {
141-
handleInvocationTimeout(response, timeout)
142-
}, timeout * 1000)
143-
])
143+
new Promise(function(resolve) {
144+
invocationTimeoutRef = setTimeout(function() {
145+
handleInvocationTimeout(response, timeout)
146+
resolve()
147+
}, timeout * 1000)
148+
})
149+
]).finally(() => {
150+
clearTimeout(invocationTimeoutRef)
151+
})
144152
};
145153
}
146154

0 commit comments

Comments
 (0)