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

Commit

Permalink
add option to specify family for connect
Browse files Browse the repository at this point in the history
  • Loading branch information
Sophie Saskin authored and mbroadst committed Sep 4, 2018
1 parent 7197815 commit 6d82151
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/connection/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,26 @@ function makeConnection(conn, options, callback) {
return;
}

function normalConnect(conn, family, _options) {
const options = prepareConnectionOptions(conn, _options);
makeConnection(conn, Object.assign({}, { family: family }, options), (err, connection) => {
if (connection) {
// Add handlers for events
connection.once('error', errorHandler(conn));
connection.once('timeout', timeoutHandler(conn));
connection.once('close', closeHandler(conn));
connection.on('data', dataHandler(conn));
conn.connection = connection;
conn.emit('connect', conn);
conn;
}
if (err) {
const _errorHandler = errorHandler(conn);
_errorHandler(err);
}
});
}

function fastFallbackConnect(conn, _options, callback) {
const options = prepareConnectionOptions(conn, _options);

Expand Down Expand Up @@ -654,6 +674,10 @@ Connection.prototype.connect = function(_options) {
this.responseOptions.promoteBuffers = _options.promoteBuffers;
}

if (this.family !== void 0) {
return normalConnect(this, this.family, _options);
}

return fastFallbackConnect(this, _options, (err, connection) => {
if (err) {
this.emit('error', err, this);
Expand Down

0 comments on commit 6d82151

Please sign in to comment.