Close this topology
()
| 498 | |
| 499 | /** Close this topology */ |
| 500 | close(): void { |
| 501 | if (this.s.state === STATE_CLOSED || this.s.state === STATE_CLOSING) { |
| 502 | return; |
| 503 | } |
| 504 | |
| 505 | for (const server of this.s.servers.values()) { |
| 506 | closeServer(server, this); |
| 507 | } |
| 508 | |
| 509 | this.s.servers.clear(); |
| 510 | |
| 511 | stateTransition(this, STATE_CLOSING); |
| 512 | |
| 513 | drainWaitQueue(this.waitQueue, new MongoTopologyClosedError()); |
| 514 | |
| 515 | if (this.s.srvPoller) { |
| 516 | this.s.srvPoller.stop(); |
| 517 | this.s.srvPoller.removeListener(SrvPoller.SRV_RECORD_DISCOVERY, this.s.detectSrvRecords); |
| 518 | } |
| 519 | |
| 520 | this.removeListener(Topology.TOPOLOGY_DESCRIPTION_CHANGED, this.s.detectShardedTopology); |
| 521 | |
| 522 | stateTransition(this, STATE_CLOSED); |
| 523 | |
| 524 | // emit an event for close |
| 525 | this.emitAndLog(Topology.TOPOLOGY_CLOSED, new TopologyClosedEvent(this.s.id)); |
| 526 | } |
| 527 | |
| 528 | /** |
| 529 | * Selects a server according to the selection predicate provided |
no test coverage detected