-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
Returning this in net and its inheriting prototype methods #1657
Copy link
Copy link
Closed
Labels
httpIssues or PRs related to the http subsystem.Issues or PRs related to the http subsystem.httpsIssues or PRs related to the https subsystem.Issues or PRs related to the https subsystem.netIssues and PRs related to the net subsystem.Issues and PRs related to the net subsystem.semver-minorPRs that contain new features and should be released in the next minor version.PRs that contain new features and should be released in the next minor version.tlsIssues and PRs related to the tls subsystem.Issues and PRs related to the tls subsystem.
Metadata
Metadata
Assignees
Labels
httpIssues or PRs related to the http subsystem.Issues or PRs related to the http subsystem.httpsIssues or PRs related to the https subsystem.Issues or PRs related to the https subsystem.netIssues and PRs related to the net subsystem.Issues and PRs related to the net subsystem.semver-minorPRs that contain new features and should be released in the next minor version.PRs that contain new features and should be released in the next minor version.tlsIssues and PRs related to the tls subsystem.Issues and PRs related to the tls subsystem.
One typical way to create a server is through
Then we export the server for other purposes (testing, for example)
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:
At this time, errors might occur because unlike
server.listen,server.setTimeoutdoes not return the instance ofhttp.server.Event through http module is labelled as stability level 3, but the documentation does not specify the return value for
server.listenand for server.setTimeout`. So maybe change the return value is not completely out of the question.I understand there are multiple
setTimeoutfunctions in various modules (likenet.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
*.setTimeoutfunctions (except thesetTimeoutin plain JavaScript).If such changes are not possible, at least we could specify the expected return values for those APIs (namely
server.listen,server.setTimeoutand some others), so that we might avoid some confusions about those APIs.