* Creates new server instances and attempts to connect them * * @param topology - The topology that this server belongs to * @param serverDescription - The description for the server to initialize and connect to
(topology: Topology, serverDescription: ServerDescription)
| 839 | * @param serverDescription - The description for the server to initialize and connect to |
| 840 | */ |
| 841 | function createAndConnectServer(topology: Topology, serverDescription: ServerDescription) { |
| 842 | topology.emitAndLog( |
| 843 | Topology.SERVER_OPENING, |
| 844 | new ServerOpeningEvent(topology.s.id, serverDescription.address) |
| 845 | ); |
| 846 | |
| 847 | const server = new Server(topology, serverDescription, topology.s.options); |
| 848 | for (const event of SERVER_RELAY_EVENTS) { |
| 849 | server.on(event, (e: any) => topology.emit(event, e)); |
| 850 | } |
| 851 | |
| 852 | server.on(Server.DESCRIPTION_RECEIVED, description => topology.serverUpdateHandler(description)); |
| 853 | |
| 854 | server.connect(); |
| 855 | return server; |
| 856 | } |
| 857 | |
| 858 | /** |
| 859 | * @param topology - Topology to update. |
no test coverage detected