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

Function monitorServer

src/sdam/monitor.ts:426–461  ·  view source on GitHub ↗
(monitor: Monitor)

Source from the content-addressed store, hash-verified

424}
425
426function monitorServer(monitor: Monitor) {
427 return (callback: Callback) => {
428 if (monitor.s.state === STATE_MONITORING) {
429 queueMicrotask(callback);
430 return;
431 }
432 stateTransition(monitor, STATE_MONITORING);
433 function done() {
434 if (!isInCloseState(monitor)) {
435 stateTransition(monitor, STATE_IDLE);
436 }
437
438 callback();
439 }
440
441 checkServer(monitor, (err, hello) => {
442 if (err) {
443 // otherwise an error occurred on initial discovery, also bail
444 if (monitor.server.description.type === ServerType.Unknown) {
445 return done();
446 }
447 }
448
449 // if the check indicates streaming is supported, immediately reschedule monitoring
450 if (useStreamingProtocol(monitor, hello?.topologyVersion)) {
451 setTimeout(() => {
452 if (!isInCloseState(monitor)) {
453 monitor.monitorId?.wake();
454 }
455 }, 0);
456 }
457
458 done();
459 });
460 };
461}
462
463function makeTopologyVersion(tv: TopologyVersion) {
464 return {

Callers 2

connectMethod · 0.85
resetMethod · 0.85

Calls 5

checkServerFunction · 0.85
useStreamingProtocolFunction · 0.85
isInCloseStateFunction · 0.85
wakeMethod · 0.80
doneFunction · 0.70

Tested by

no test coverage detected