Skip to content

Commit 46b5df0

Browse files
sagirkrvagg
authored andcommitted
test: refactor test to use arrow functions
In `test/parallel/test-cluster-send-deadlock.js`, callbacks use anonymous closure functions. It is safe to replace them with arrow functions since these callbacks don't contain references to `this`, `super` or `arguments`. This results in shorter functions. PR-URL: #24479 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
1 parent c28ec86 commit 46b5df0

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

test/parallel/test-cluster-send-deadlock.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -30,42 +30,42 @@ const net = require('net');
3030

3131
if (cluster.isMaster) {
3232
const worker = cluster.fork();
33-
worker.on('exit', function(code, signal) {
33+
worker.on('exit', (code, signal) => {
3434
assert.strictEqual(code, 0, `Worker exited with an error code: ${code}`);
3535
assert(!signal, `Worker exited by a signal: ${signal}`);
3636
server.close();
3737
});
3838

39-
const server = net.createServer(function(socket) {
39+
const server = net.createServer((socket) => {
4040
worker.send('handle', socket);
4141
});
4242

43-
server.listen(0, function() {
43+
server.listen(0, () => {
4444
worker.send({ message: 'listen', port: server.address().port });
4545
});
4646
} else {
47-
process.on('message', function(msg, handle) {
47+
process.on('message', (msg, handle) => {
4848
if (msg.message && msg.message === 'listen') {
4949
assert(msg.port);
5050
const client1 = net.connect({
5151
host: 'localhost',
5252
port: msg.port
53-
}, function() {
53+
}, () => {
5454
const client2 = net.connect({
5555
host: 'localhost',
5656
port: msg.port
57-
}, function() {
57+
}, () => {
5858
client1.on('close', onclose);
5959
client2.on('close', onclose);
6060
client1.end();
6161
client2.end();
6262
});
6363
});
6464
let waiting = 2;
65-
function onclose() {
65+
const onclose = () => {
6666
if (--waiting === 0)
6767
cluster.worker.disconnect();
68-
}
68+
};
6969
} else {
7070
process.send('reply', handle);
7171
}

0 commit comments

Comments
 (0)