Skip to content

Commit

Permalink
Update serve.js to clear the timeout if a function invocation is a su…
Browse files Browse the repository at this point in the history
…ccess within the timeout.
  • Loading branch information
alexanderson1993 committed Feb 13, 2019
1 parent 6f470ae commit 20cb467
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,20 @@ function createHandler(dir, static, timeout) {
{ clientContext: buildClientContext(request.headers) || {} },
callback
);

var invocationTimeoutRef = null

Promise.race([
promiseCallback(promise, callback),
setTimeout(function() {
handleInvocationTimeout(response, timeout)
}, timeout * 1000)
])
new Promise(function(resolve) {
invocationTimeoutRef = setTimeout(function() {
handleInvocationTimeout(response, timeout)
resolve()
}, timeout * 1000)
})
]).finally(() => {
clearTimeout(invocationTimeoutRef)
})
};
}

Expand Down

0 comments on commit 20cb467

Please sign in to comment.