Skip to content

Commit 0d97255

Browse files
committed
don't construct Timeout when not needed
1 parent 2173c14 commit 0d97255

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/sdam/topology.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -583,12 +583,14 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
583583
}
584584

585585
const { promise: serverPromise, resolve, reject } = promiseWithResolvers<Server>();
586-
console.log(options.timeout?.remainingTime, options.serverSelectionTimeoutMS);
587-
const timeout = options.timeout
588-
? Timeout.expires(
589-
Timeout.min(options.timeout.remainingTime, options.serverSelectionTimeoutMS ?? 0)
590-
)
591-
: Timeout.expires(options.serverSelectionTimeoutMS ?? 0);
586+
const serverSelectionTimeoutMS = options.serverSelectionTimeoutMS ?? 0;
587+
let timeout: Timeout;
588+
if (options.timeout && options.timeout.remainingTime < serverSelectionTimeoutMS) {
589+
timeout = options.timeout;
590+
} else {
591+
timeout = Timeout.expires(serverSelectionTimeoutMS);
592+
}
593+
592594
const waitQueueMember: ServerSelectionRequest = {
593595
serverSelector,
594596
topologyDescription: this.description,

0 commit comments

Comments
 (0)