@@ -61,15 +61,36 @@ export interface CursorStreamOptions {
61
61
/** @public */
62
62
export type CursorFlag = ( typeof CURSOR_FLAGS ) [ number ] ;
63
63
64
- /** @public */
64
+ /** @public */
65
65
export const CursorTimeoutMode = Object . freeze ( {
66
66
ITERATION : 'iteration' ,
67
67
LIFETIME : 'cursorLifetime'
68
68
} as const ) ;
69
69
70
70
/** @public
71
- * TODO(NODE-5688): Document and release
72
- * */
71
+ * Specifies how `timeoutMS` is applied to the cursor. Can be either `'cursorLifeTime'` or `'iteration'`
72
+ * When set to `'iteration'`, the deadline specified by `timeoutMS` applies to each call of
73
+ * `cursor.next()`.
74
+ * When set to `'cursorLifetime'`, the deadline applies to the life of the entire cursor.
75
+ *
76
+ * @example
77
+ * # Example showing use of `'iteration'`
78
+ * ```ts
79
+ * const cursor = collection.find({}, {timeoutMS: 100, timeoutMode: 'iteration'});
80
+ * for await (const doc of cursor) {
81
+ * // process doc
82
+ * // This will throw a timeout error if any of the iterator's `next()` calls takes more than 100ms, but
83
+ * will continue to iterate successfully otherwise, regardless of the number of batches.
84
+ * }
85
+ * ```
86
+ *
87
+ * # Example showing use of `'cursorLifetime'`
88
+ *
89
+ * ```ts
90
+ * const cursor = collection.find({}, { timeoutMS: 1000, timeoutMode: 'cursorLifetime' });
91
+ * const docs = await cursor.toArray(); // This entire line will throw a timeout error if all batches are not fetched and returned within 1000ms.
92
+ * ```
93
+ */
73
94
export type CursorTimeoutMode = ( typeof CursorTimeoutMode ) [ keyof typeof CursorTimeoutMode ] ;
74
95
75
96
/** @public */
@@ -115,9 +136,32 @@ export interface AbstractCursorOptions extends BSONSerializeOptions {
115
136
*/
116
137
awaitData ?: boolean ;
117
138
noCursorTimeout ?: boolean ;
118
- /** @internal TODO(NODE-5688): make this public */
139
+ /** Specifies the time an operation will run until it throws a timeout error. See { @link AbstractCursorOptions.timeoutMode} for more details. */
119
140
timeoutMS ?: number ;
120
- /** @internal TODO(NODE-5688): make this public */
141
+ /**
142
+ * Specifies how `timeoutMS` is applied to the cursor. Can be either `'cursorLifeTime'` or `'iteration'`
143
+ * When set to `'iteration'`, the deadline specified by `timeoutMS` applies to each call of
144
+ * `cursor.next()`.
145
+ * When set to `'cursorLifetime'`, the deadline applies to the life of the entire cursor.
146
+ *
147
+ * @example
148
+ * # Example showing use of `'iteration'`
149
+ * ```ts
150
+ * const cursor = collection.find({}, {timeoutMS: 100, timeoutMode: 'iteration'});
151
+ * for await (const doc of cursor) {
152
+ * // process doc
153
+ * // This will throw a timeout error if any of the iterator's `next()` calls takes more than 100ms, but
154
+ * will continue to iterate successfully otherwise, regardless of the number of batches.
155
+ * }
156
+ * ```
157
+ *
158
+ * # Example showing use of `'cursorLifetime'`
159
+ *
160
+ * ```ts
161
+ * const cursor = collection.find({}, { timeoutMS: 1000, timeoutMode: 'cursorLifetime' });
162
+ * const docs = await cursor.toArray(); // This entire line will throw a timeout error if all batches are not fetched and returned within 1000ms.
163
+ * ```
164
+ */
121
165
timeoutMode ?: CursorTimeoutMode ;
122
166
123
167
/**
0 commit comments