Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.

Commit 41e3d5e

Browse files
committed
style(connection): minor stylistic changes
1 parent ccde817 commit 41e3d5e

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

lib/connection/connection.js

+20-22
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ function prepareConnectionOptions(conn, _options) {
572572
options = { port: conn.port, host: conn.host };
573573
}
574574
}
575+
575576
return options;
576577
}
577578

@@ -598,19 +599,13 @@ function makeConnection(conn, options, callback) {
598599

599600
// Add handlers for events
600601
connection.once('error', err => callback(err, null));
601-
602-
return;
603602
}
604603

605604
function normalConnect(conn, family, _options, callback) {
606605
const options = prepareConnectionOptions(conn, _options);
607606
makeConnection(conn, Object.assign({}, { family: family }, options), (err, connection) => {
608-
if (connection) {
609-
return callback(null, connection);
610-
}
611-
if (err) {
612-
return callback(err, null);
613-
}
607+
if (err) return callback(err, null);
608+
callback(null, connection);
614609
});
615610
}
616611

@@ -620,27 +615,28 @@ function fastFallbackConnect(conn, _options, callback) {
620615
let errors = [];
621616
let connection;
622617
const connectionHandler = (err, _connection) => {
623-
if (_connection) {
624-
if (connection) {
625-
_connection.removeAllListeners('error');
626-
_connection.unref();
627-
return;
628-
}
629-
connection = _connection;
630-
return callback(null, connection);
631-
}
632618
if (err) {
633619
if (errors.length > 0) {
634620
// an error occurred for the second time, we have officially failed
635-
636621
// return mongo error to be emitted
637622
return callback(err, null);
638623
}
624+
639625
// otherwise push the error, and wait for subsequent connects
640-
// if (connectionAccounting) deleteConnection(conn.id);
641626
errors.push(err);
642627
return;
643628
}
629+
630+
if (_connection) {
631+
if (connection) {
632+
_connection.removeAllListeners('error');
633+
_connection.unref();
634+
return;
635+
}
636+
637+
connection = _connection;
638+
return callback(null, connection);
639+
}
644640
};
645641

646642
makeConnection(conn, Object.assign({}, { family: 6 }, options), connectionHandler);
@@ -667,13 +663,15 @@ Connection.prototype.connect = function(_options) {
667663
}
668664

669665
const connectHandler = (err, connection) => {
666+
const connectionErrorHandler = errorHandler(this);
667+
670668
if (err) {
671-
const _errorHandler = errorHandler(this);
672-
_errorHandler(err);
669+
connectionErrorHandler(err);
673670
return;
674671
}
672+
675673
// Add handlers for events
676-
connection.once('error', errorHandler(this));
674+
connection.once('error', connectionErrorHandler);
677675
connection.once('timeout', timeoutHandler(this));
678676
connection.once('close', closeHandler(this));
679677
connection.on('data', dataHandler(this));

0 commit comments

Comments
 (0)