Skip to content

Commit

Permalink
optional chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
mrluanma committed Mar 12, 2024
1 parent 4129ef1 commit 1449c51
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
14 changes: 5 additions & 9 deletions local.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,19 +251,17 @@ var server = net.createServer(function (connection) {

connection.on('end', function () {
console.log('local disconnected');
if (ws) {
ws.terminate();
}
ws?.terminate();

server.getConnections(function (err, count) {
console.log('concurrent connections:', count);
});
});

connection.on('error', function (e) {
console.log(`local error: ${e}`);
if (ws) {
ws.terminate();
}
ws?.terminate();

server.getConnections(function (err, count) {
console.log('concurrent connections:', count);
});
Expand All @@ -272,9 +270,7 @@ var server = net.createServer(function (connection) {
connection.setTimeout(timeout, function () {
console.log('local timeout');
connection.destroy();
if (ws) {
ws.terminate();
}
ws?.terminate();
});
});

Expand Down
8 changes: 2 additions & 6 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,13 @@ wss.on('connection', function (ws) {
ws.on('close', function () {
console.log('server disconnected');
console.log('concurrent connections:', wss.clients.size);
if (remote) {
remote.destroy();
}
remote?.destroy();
});

ws.on('error', function (e) {
console.warn(`server: ${e}`);
console.log('concurrent connections:', wss.clients.size);
if (remote) {
remote.destroy();
}
remote?.destroy();
});
});

Expand Down

0 comments on commit 1449c51

Please sign in to comment.