Skip to content

Commit

Permalink
refactor(NODE-6187): refactor to use TimeoutContext abstraction (#4131)
Browse files Browse the repository at this point in the history
  • Loading branch information
W-A-James committed Oct 14, 2024
1 parent 450b163 commit a5e5e6d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/operations/execute_operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ type ResultTypeFromOperation<TOperation> =
export async function executeOperation<
T extends AbstractOperation<TResult>,
TResult = ResultTypeFromOperation<T>
<<<<<<< HEAD
>(client: MongoClient, operation: T, timeoutContext?: TimeoutContext | null): Promise<TResult> {
=======
>(client: MongoClient, operation: T, timeoutContext?: TimeoutContext): Promise<TResult> {
>>>>>>> e04694c3b (refactor(NODE-6187): refactor to use TimeoutContext abstraction (#4131))
if (!(operation instanceof AbstractOperation)) {
// TODO(NODE-3483): Extend MongoRuntimeError
throw new MongoRuntimeError('This method requires a valid operation instance');
Expand All @@ -82,6 +86,12 @@ export async function executeOperation<
throw new MongoInvalidArgumentError('ClientSession must be from the same MongoClient');
}

timeoutContext ??= TimeoutContext.create({
serverSelectionTimeoutMS: client.s.options.serverSelectionTimeoutMS,
waitQueueTimeoutMS: client.s.options.waitQueueTimeoutMS,
timeoutMS: operation.options.timeoutMS
});

const readPreference = operation.readPreference ?? ReadPreference.primary;
const inTransaction = !!session?.inTransaction();

Expand Down Expand Up @@ -113,7 +123,8 @@ export async function executeOperation<
topology,
timeoutContext,
session,
readPreference
readPreference,
timeoutContext
});
} finally {
if (session?.owner != null && session.owner === owner) {
Expand Down

0 comments on commit a5e5e6d

Please sign in to comment.