Skip to content

Commit 08be6d4

Browse files
committed
Add timeoutMode to abstract cursor and add validation
1 parent c2b8b24 commit 08be6d4

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/cursor/abstract_cursor.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export interface AbstractCursorOptions extends BSONSerializeOptions {
111111
noCursorTimeout?: boolean;
112112
/** @internal TODO(NODE-5688): make this public */
113113
timeoutMS?: number;
114+
timeoutMode?: CursorTimeoutMode;
114115
}
115116

116117
/** @internal */
@@ -189,6 +190,26 @@ export abstract class AbstractCursor<
189190
...pluckBSONSerializeOptions(options)
190191
};
191192
this.cursorOptions.timeoutMS = options.timeoutMS;
193+
if (this.cursorOptions.timeoutMS != null) {
194+
this.cursorOptions.timeoutMode = options.timeoutMode;
195+
}
196+
197+
if (this.cursorOptions.timeoutMS != null) {
198+
if (this.cursorOptions.timeoutMode == null) {
199+
if (this.cursorOptions.tailable) {
200+
this.cursorOptions.timeoutMode = CursorTimeoutMode.ITERATION;
201+
} else {
202+
this.cursorOptions.timeoutMode = CursorTimeoutMode.LIFETIME;
203+
}
204+
} else {
205+
if (
206+
this.cursorOptions.tailable &&
207+
this.cursorOptions.timeoutMode === CursorTimeoutMode.LIFETIME
208+
) {
209+
throw new MongoAPIError("Cannot set tailable cursor's timeoutMode to LIFETIME");
210+
}
211+
}
212+
}
192213

193214
const readConcern = ReadConcern.fromOptions(options);
194215
if (readConcern) {

0 commit comments

Comments
 (0)