Skip to content
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

child_process: refactor self=this in socket_list #5860

Closed

Conversation

benjamingr
Copy link
Member

Pull Request check-list

Affected core subsystem(s)

child_process

Description of change

The socket list module (used by child_process) currently uses the var self = this; pattern for context in several places, this PR replaces this with arrow functions or passing a parameter in where appropriate.

Note that the var self = this in the _request is intentionally left in place since it is not trivial to refactor it and the current pattern isn't bad given the use case.

The socket list module (used by child_process) currently uses the
`var self = this;` pattern for context in several places, this PR
replaces this with arrow functions or passing a parameter in where
appropriate.

Note that the `var self = this` in the _request is intentioanlly
left in place since it is not trivial to refactor it and the current
pattern isn't bad given the use case.

PR-URL:
Reviewed-By:
Reviewed-By:
@benjamingr benjamingr added the child_process Issues and PRs related to the child_process subsystem. label Mar 23, 2016
@mscdex
Copy link
Contributor

mscdex commented Mar 23, 2016

@cjihrig
Copy link
Contributor

cjihrig commented Mar 23, 2016

LGTM, and CI is green.

@jasnell
Copy link
Member

jasnell commented Mar 23, 2016

LGTM, CI is green


if (self.connections === 0) self.emit('empty');
if (this.connections === 0) this.emit('empty', this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does the passed this end up here? Seems unnecessary?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It gets passed to onempty() which is the empty event handler added on line 82.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To send the context as a parameter seems ambigous. Since we are using arrow functions, why not just binding the method l.82 ? onempty.bind(this)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ludoblues bind is slow and it makes the resulting function slow too. It is also very scarcely used in Node where this pattern is very common. See http://stackoverflow.com/questions/17638305/why-is-bind-slower-than-a-closure

@benjamingr
Copy link
Member Author

Landed in a6b9b55

@benjamingr benjamingr closed this Mar 27, 2016
benjamingr added a commit that referenced this pull request Mar 27, 2016
The socket list module (used by child_process) currently uses the
`var self = this;` pattern for context in several places, this PR
replaces this with arrow functions or passing a parameter in where
appropriate.

Note that the `var self = this` in the _request is intentioanlly
left in place since it is not trivial to refactor it and the current
pattern isn't bad given the use case.

PR-URL: #5860
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
evanlucas pushed a commit that referenced this pull request Mar 30, 2016
The socket list module (used by child_process) currently uses the
`var self = this;` pattern for context in several places, this PR
replaces this with arrow functions or passing a parameter in where
appropriate.

Note that the `var self = this` in the _request is intentioanlly
left in place since it is not trivial to refactor it and the current
pattern isn't bad given the use case.

PR-URL: #5860
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
evanlucas pushed a commit that referenced this pull request Mar 31, 2016
The socket list module (used by child_process) currently uses the
`var self = this;` pattern for context in several places, this PR
replaces this with arrow functions or passing a parameter in where
appropriate.

Note that the `var self = this` in the _request is intentioanlly
left in place since it is not trivial to refactor it and the current
pattern isn't bad given the use case.

PR-URL: #5860
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
MylesBorins pushed a commit that referenced this pull request Apr 8, 2016
The socket list module (used by child_process) currently uses the
`var self = this;` pattern for context in several places, this PR
replaces this with arrow functions or passing a parameter in where
appropriate.

Note that the `var self = this` in the _request is intentioanlly
left in place since it is not trivial to refactor it and the current
pattern isn't bad given the use case.

PR-URL: #5860
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
@MylesBorins MylesBorins mentioned this pull request Apr 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
child_process Issues and PRs related to the child_process subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants