Skip to content

Commit

Permalink
refactor: support a factory type in connect
Browse files Browse the repository at this point in the history
This allows for easier testing, as well as potentially supporting
multiple `Connection` types during our CMAP work
  • Loading branch information
mbroadst committed Nov 11, 2019
1 parent 51e8807 commit ba123a6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/core/connection/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const MIN_SUPPORTED_SERVER_VERSION = WIRE_CONSTANTS.MIN_SUPPORTED_SERVER_VERSION
let AUTH_PROVIDERS;

function connect(options, callback) {
const ConnectionType = options && options.connectionType ? options.connectionType : Connection;
if (AUTH_PROVIDERS == null) {
AUTH_PROVIDERS = defaultAuthProviders(options.bson);
}
Expand All @@ -26,7 +27,7 @@ function connect(options, callback) {
return;
}

performInitialHandshake(new Connection(socket, options), options, callback);
performInitialHandshake(new ConnectionType(socket, options), options, callback);
});

return;
Expand All @@ -40,13 +41,13 @@ function connect(options, callback) {
return;
}

performInitialHandshake(new Connection(ipv4Socket, options), options, callback);
performInitialHandshake(new ConnectionType(ipv4Socket, options), options, callback);
});

return;
}

performInitialHandshake(new Connection(ipv6Socket, options), options, callback);
performInitialHandshake(new ConnectionType(ipv6Socket, options), options, callback);
});
}

Expand Down

0 comments on commit ba123a6

Please sign in to comment.