-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
Description
One typical way to create a server is through
http.createServer(callback).listen(port);
Then we export the server for other purposes (testing, for example)
module.exports = http.createServer(callback).listen(port);
At this point, everything works as expected.
Later on, when we are trying to add a timeout to the http.Server, we might be tempted to write something like this:
module.exports = http.createServer(callback).listen(port).setTimeout(timeout);
At this time, errors might occur because unlike server.listen
, server.setTimeout
does not return the instance of http.server
.
Event through http module is labelled as stability level 3, but the documentation does not specify the return value for server.listen
and for server.setTimeout`. So maybe change the return value is not completely out of the question.
I understand there are multiple setTimeout
functions in various modules (like net.setTimeout
, message.setTimeout
, server.setTimeout
, and so on).
Maybe we could consider return http.Server for server.setTimeout(), or even return corresponding instances for all *.setTimeout
functions (except the setTimeout
in plain JavaScript).
If such changes are not possible, at least we could specify the expected return values for those APIs (namely server.listen
, server.setTimeout
and some others), so that we might avoid some confusions about those APIs.