@@ -21,7 +21,7 @@ import { ReadPreference, type ReadPreferenceLike } from '../read_preference';
21
21
import { type AsyncDisposable , configureResourceManagement } from '../resource_management' ;
22
22
import type { Server } from '../sdam/server' ;
23
23
import { ClientSession , maybeClearPinnedConnection } from '../sessions' ;
24
- import { TimeoutContext } from '../timeout' ;
24
+ import { type CSOTTimeoutContext , type Timeout , TimeoutContext } from '../timeout' ;
25
25
import { type MongoDBNamespace , squashError } from '../utils' ;
26
26
27
27
/**
@@ -119,6 +119,9 @@ export interface AbstractCursorOptions extends BSONSerializeOptions {
119
119
timeoutMS ?: number ;
120
120
/** @internal TODO(NODE-5688): make this public */
121
121
timeoutMode ?: CursorTimeoutMode ;
122
+
123
+ /** @internal */
124
+ timeoutContext ?: CursorTimeoutContext ;
122
125
}
123
126
124
127
/** @internal */
@@ -140,6 +143,46 @@ export type AbstractCursorEvents = {
140
143
[ AbstractCursor . CLOSE ] ( ) : void ;
141
144
} ;
142
145
146
+ export class CursorTimeoutContext extends TimeoutContext {
147
+ constructor (
148
+ public timeoutContext : TimeoutContext ,
149
+ public owner : AbstractCursor | null = null
150
+ ) {
151
+ super ( ) ;
152
+ }
153
+
154
+ override get serverSelectionTimeout ( ) : Timeout | null {
155
+ return this . timeoutContext . serverSelectionTimeout ;
156
+ }
157
+ override get connectionCheckoutTimeout ( ) : Timeout | null {
158
+ return this . timeoutContext . connectionCheckoutTimeout ;
159
+ }
160
+ override get clearServerSelectionTimeout ( ) : boolean {
161
+ return this . timeoutContext . clearServerSelectionTimeout ;
162
+ }
163
+ override get clearConnectionCheckoutTimeout ( ) : boolean {
164
+ return this . timeoutContext . clearConnectionCheckoutTimeout ;
165
+ }
166
+ override get timeoutForSocketWrite ( ) : Timeout | null {
167
+ return this . timeoutContext . timeoutForSocketWrite ;
168
+ }
169
+ override get timeoutForSocketRead ( ) : Timeout | null {
170
+ return this . timeoutContext . timeoutForSocketRead ;
171
+ }
172
+ override csotEnabled ( ) : this is CSOTTimeoutContext {
173
+ return this . timeoutContext . csotEnabled ( ) ;
174
+ }
175
+ override refresh ( ) : void {
176
+ return this . timeoutContext . refresh ( ) ;
177
+ }
178
+ override clear ( ) : void {
179
+ return this . timeoutContext . clear ( ) ;
180
+ }
181
+ override refreshed ( ) : TimeoutContext {
182
+ return new CursorTimeoutContext ( this . timeoutContext . refreshed ( ) , this . owner ) ;
183
+ }
184
+ }
185
+
143
186
/** @public */
144
187
export abstract class AbstractCursor <
145
188
TSchema = any ,
@@ -171,7 +214,7 @@ export abstract class AbstractCursor<
171
214
/** @internal */
172
215
protected readonly cursorOptions : InternalAbstractCursorOptions ;
173
216
/** @internal */
174
- protected timeoutContext ?: TimeoutContext ;
217
+ protected timeoutContext ?: CursorTimeoutContext ;
175
218
176
219
/** @event */
177
220
static readonly CLOSE = 'close' as const ;
@@ -264,6 +307,8 @@ export abstract class AbstractCursor<
264
307
utf8 : options ?. enableUtf8Validation === false ? false : true
265
308
}
266
309
} ;
310
+
311
+ this . timeoutContext = options . timeoutContext ;
267
312
}
268
313
269
314
/**
@@ -790,10 +835,13 @@ export abstract class AbstractCursor<
790
835
*/
791
836
private async cursorInit ( ) : Promise < void > {
792
837
if ( this . cursorOptions . timeoutMS != null ) {
793
- this . timeoutContext = TimeoutContext . create ( {
794
- serverSelectionTimeoutMS : this . client . options . serverSelectionTimeoutMS ,
795
- timeoutMS : this . cursorOptions . timeoutMS
796
- } ) ;
838
+ this . timeoutContext = new CursorTimeoutContext (
839
+ TimeoutContext . create ( {
840
+ serverSelectionTimeoutMS : this . client . options . serverSelectionTimeoutMS ,
841
+ timeoutMS : this . cursorOptions . timeoutMS
842
+ } ) ,
843
+ this
844
+ ) ;
797
845
}
798
846
try {
799
847
const state = await this . _initialize ( this . cursorSession ) ;
0 commit comments