Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 660ec9f

Browse filesBrowse files
benjamingrevanlucas
authored andcommitted
child_process: refactor self=this in socket_list
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>
1 parent 58b5c1e commit 660ec9f
Copy full SHA for 660ec9f

File tree

Expand file treeCollapse file tree

1 file changed

+12
-16
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+12
-16
lines changed
Open diff view settings
Collapse file

‎lib/internal/socket_list.js‎

Copy file name to clipboardExpand all lines: lib/internal/socket_list.js
+12-16Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,11 @@ SocketListSend.prototype.getConnections = function getConnections(callback) {
5858
function SocketListReceive(slave, key) {
5959
EventEmitter.call(this);
6060

61-
var self = this;
62-
6361
this.connections = 0;
6462
this.key = key;
6563
this.slave = slave;
6664

67-
function onempty() {
65+
function onempty(self) {
6866
if (!self.slave.connected) return;
6967

7068
self.slave.send({
@@ -73,36 +71,34 @@ function SocketListReceive(slave, key) {
7371
});
7472
}
7573

76-
this.slave.on('internalMessage', function(msg) {
77-
if (msg.key !== self.key) return;
74+
this.slave.on('internalMessage', (msg) => {
75+
if (msg.key !== this.key) return;
7876

7977
if (msg.cmd === 'NODE_SOCKET_NOTIFY_CLOSE') {
8078
// Already empty
81-
if (self.connections === 0) return onempty();
79+
if (this.connections === 0) return onempty(this);
8280

8381
// Wait for sockets to get closed
84-
self.once('empty', onempty);
82+
this.once('empty', onempty);
8583
} else if (msg.cmd === 'NODE_SOCKET_GET_COUNT') {
86-
if (!self.slave.connected) return;
87-
self.slave.send({
84+
if (!this.slave.connected) return;
85+
this.slave.send({
8886
cmd: 'NODE_SOCKET_COUNT',
89-
key: self.key,
90-
count: self.connections
87+
key: this.key,
88+
count: this.connections
9189
});
9290
}
9391
});
9492
}
9593
util.inherits(SocketListReceive, EventEmitter);
9694

9795
SocketListReceive.prototype.add = function(obj) {
98-
var self = this;
99-
10096
this.connections++;
10197

10298
// Notify previous owner of socket about its state change
103-
obj.socket.once('close', function() {
104-
self.connections--;
99+
obj.socket.once('close', () => {
100+
this.connections--;
105101

106-
if (self.connections === 0) self.emit('empty');
102+
if (this.connections === 0) this.emit('empty', this);
107103
});
108104
};

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.