summaryrefslogtreecommitdiff
path: root/lib/cluster.js
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2016-07-13 11:18:31 -0400
committercjihrig <cjihrig@gmail.com>2016-07-15 10:01:17 -0400
commit45367a2a8fca611279fe8e18b2af244564da7616 (patch)
treecf088120c0275ef58ee1e1b8fbae47b9da11c404 /lib/cluster.js
parent9dc06516573b9b05dab88c9e07445dda067114c3 (diff)
downloadandroid-node-v8-45367a2a8fca611279fe8e18b2af244564da7616.tar.gz
android-node-v8-45367a2a8fca611279fe8e18b2af244564da7616.tar.bz2
android-node-v8-45367a2a8fca611279fe8e18b2af244564da7616.zip
cluster: remove bind() and self
This commit removes the use of self and bind() from the cluster module in favor of arrow functions. PR-URL: https://github.com/nodejs/node/pull/7710 Reviewed-By: Michaƫl Zasso <mic.besace@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Minwoo Jung <jmwsoft@gmail.com>
Diffstat (limited to 'lib/cluster.js')
-rw-r--r--lib/cluster.js34
1 files changed, 16 insertions, 18 deletions
diff --git a/lib/cluster.js b/lib/cluster.js
index b4e2ea42dd..38e6885f67 100644
--- a/lib/cluster.js
+++ b/lib/cluster.js
@@ -128,12 +128,11 @@ function RoundRobinHandle(key, address, port, addressType, backlog, fd) {
else
this.server.listen(address); // UNIX socket path.
- var self = this;
- this.server.once('listening', function() {
- self.handle = self.server._handle;
- self.handle.onconnection = self.distribute.bind(self);
- self.server._handle = null;
- self.server = null;
+ this.server.once('listening', () => {
+ this.handle = this.server._handle;
+ this.handle.onconnection = (err, handle) => this.distribute(err, handle);
+ this.server._handle = null;
+ this.server = null;
});
}
@@ -141,18 +140,17 @@ RoundRobinHandle.prototype.add = function(worker, send) {
assert(worker.id in this.all === false);
this.all[worker.id] = worker;
- var self = this;
- function done() {
- if (self.handle.getsockname) {
+ const done = () => {
+ if (this.handle.getsockname) {
var out = {};
- self.handle.getsockname(out);
+ this.handle.getsockname(out);
// TODO(bnoordhuis) Check err.
send(null, { sockname: out }, null);
} else {
send(null, null, null); // UNIX socket.
}
- self.handoff(worker); // In case there are connections pending.
- }
+ this.handoff(worker); // In case there are connections pending.
+ };
if (this.server === null) return done();
// Still busy binding.
@@ -194,13 +192,13 @@ RoundRobinHandle.prototype.handoff = function(worker) {
return;
}
var message = { act: 'newconn', key: this.key };
- var self = this;
- sendHelper(worker.process, message, handle, function(reply) {
+
+ sendHelper(worker.process, message, handle, (reply) => {
if (reply.accepted)
handle.close();
else
- self.distribute(0, handle); // Worker is shutting down. Send to another.
- self.handoff(worker);
+ this.distribute(0, handle); // Worker is shutting down. Send to another.
+ this.handoff(worker);
});
};
@@ -415,7 +413,7 @@ function masterInit() {
cluster.disconnect = function(cb) {
var workers = Object.keys(cluster.workers);
if (workers.length === 0) {
- process.nextTick(intercom.emit.bind(intercom, 'disconnect'));
+ process.nextTick(() => intercom.emit('disconnect'));
} else {
for (var key in workers) {
key = workers[key];
@@ -437,7 +435,7 @@ function masterInit() {
signo = signo || 'SIGTERM';
var proc = this.process;
if (this.isConnected()) {
- this.once('disconnect', proc.kill.bind(proc, signo));
+ this.once('disconnect', () => proc.kill(signo));
this.disconnect();
return;
}