Skip to content

Commit ba123a6

Browse files
committed
refactor: support a factory type in connect
This allows for easier testing, as well as potentially supporting multiple `Connection` types during our CMAP work
1 parent 51e8807 commit ba123a6

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/core/connection/connect.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const MIN_SUPPORTED_SERVER_VERSION = WIRE_CONSTANTS.MIN_SUPPORTED_SERVER_VERSION
1515
let AUTH_PROVIDERS;
1616

1717
function connect(options, callback) {
18+
const ConnectionType = options && options.connectionType ? options.connectionType : Connection;
1819
if (AUTH_PROVIDERS == null) {
1920
AUTH_PROVIDERS = defaultAuthProviders(options.bson);
2021
}
@@ -26,7 +27,7 @@ function connect(options, callback) {
2627
return;
2728
}
2829

29-
performInitialHandshake(new Connection(socket, options), options, callback);
30+
performInitialHandshake(new ConnectionType(socket, options), options, callback);
3031
});
3132

3233
return;
@@ -40,13 +41,13 @@ function connect(options, callback) {
4041
return;
4142
}
4243

43-
performInitialHandshake(new Connection(ipv4Socket, options), options, callback);
44+
performInitialHandshake(new ConnectionType(ipv4Socket, options), options, callback);
4445
});
4546

4647
return;
4748
}
4849

49-
performInitialHandshake(new Connection(ipv6Socket, options), options, callback);
50+
performInitialHandshake(new ConnectionType(ipv6Socket, options), options, callback);
5051
});
5152
}
5253

0 commit comments

Comments
 (0)