-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Returning this
in net and its inheriting prototype methods
#1657
Comments
Seems like an okay change to me. For consistency, all setTimeout functions in lib/ (except the global one) should be updated to return One thing to consider is that it's a permanent change. We can't retroactively change the setTimeout functions to return a token like the global setTimeout does, because that would break code that has come to rely on the previous behavior. |
We should investigate various server, net and socket methods. Some are chainable, while many are not. Like @bnoordhuis said, caution should be taken for cases where it makes sense to return something else. |
+1 to @silverwind |
Looking at just the
|
I'm +1 for returning |
Hmm, given the number of methods to change, I'd prefer them in one PR, maybe with separate commits for each method. We need to be certain that we never intend to return anything else if we go ahead. For example, what if we want to report a failure in a |
#1699 looking good so far on |
this
in net and it's inheriting prototype methods
One done, seven more socket methods to go. We'll need to check how each method reports errors, but I think they're all potential candidates. |
@evanlucas maybe we can split up the work here. Would you like to add a |
Yes. Was waiting until #1518 got ok'd and landed |
this
in net and it's inheriting prototype methodsthis
in net and its inheriting prototype methods
Did |
All done, thank everyone |
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.setTimeout
does 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.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 (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
*.setTimeout
functions (except thesetTimeout
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.The text was updated successfully, but these errors were encountered: