Skip to content

Commit 879211d

Browse files
authored
Merge pull request #121 from alexanderson1993/master
Clears the invocation timeout if the invocation is a success.
2 parents 6f470ae + 20cb467 commit 879211d

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/serve.js

Lines changed: 12 additions & 4 deletions
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)