MCPcopy
hub / github.com/mongodb/node-mongodb-native / close

Method close

src/sdam/topology.ts:500–526  ·  view source on GitHub ↗

Close this topology

()

Source from the content-addressed store, hash-verified

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

Callers 2

_connectMethod · 0.95
closeServerFunction · 0.45

Calls 6

closeServerFunction · 0.85
drainWaitQueueFunction · 0.85
removeListenerMethod · 0.80
emitAndLogMethod · 0.80
clearMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected