Skip to content

Commit 2ef8382

Browse files
author
sw-yx
committed
rewrite timeout feature for node <10
1 parent c562d7c commit 2ef8382

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

Diff for: lib/serve.js

+15-8
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,26 @@ function createHandler(dir, static, timeout) {
136136
callback
137137
);
138138

139-
var invocationTimeoutRef = null
140-
139+
var invocationTimeoutRef = null;
140+
141141
Promise.race([
142142
promiseCallback(promise, callback),
143143
new Promise(function(resolve) {
144144
invocationTimeoutRef = setTimeout(function() {
145-
handleInvocationTimeout(response, timeout)
146-
resolve()
147-
}, timeout * 1000)
145+
handleInvocationTimeout(response, timeout);
146+
resolve();
147+
}, timeout * 1000);
148148
})
149-
]).finally(() => {
150-
clearTimeout(invocationTimeoutRef)
151-
})
149+
]).then(
150+
result => {
151+
clearTimeout(invocationTimeoutRef);
152+
return result; // not used, but writing this to avoid future footguns
153+
},
154+
err => {
155+
clearTimeout(invocationTimeoutRef);
156+
throw err;
157+
}
158+
);
152159
};
153160
}
154161

0 commit comments

Comments
 (0)