@@ -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 */
@@ -116,9 +137,32 @@ export interface AbstractCursorOptions extends BSONSerializeOptions {
116
137
*/
117
138
awaitData ?: boolean ;
118
139
noCursorTimeout ?: boolean ;
119
- /** @internal TODO(NODE-5688): make this public */
140
+ /** Specifies the time an operation will run until it throws a timeout error. See { @link AbstractCursorOptions.timeoutMode} for more details. */
120
141
timeoutMS ?: number ;
121
- /** @internal TODO(NODE-5688): make this public */
142
+ /**
143
+ * Specifies how `timeoutMS` is applied to the cursor. Can be either `'cursorLifeTime'` or `'iteration'`
144
+ * When set to `'iteration'`, the deadline specified by `timeoutMS` applies to each call of
145
+ * `cursor.next()`.
146
+ * When set to `'cursorLifetime'`, the deadline applies to the life of the entire cursor.
147
+ *
148
+ * @example
149
+ * # Example showing use of `'iteration'`
150
+ * ```ts
151
+ * const cursor = collection.find({}, {timeoutMS: 100, timeoutMode: 'iteration'});
152
+ * for await (const doc of cursor) {
153
+ * // process doc
154
+ * // This will throw a timeout error if any of the iterator's `next()` calls takes more than 100ms, but
155
+ * will continue to iterate successfully otherwise, regardless of the number of batches.
156
+ * }
157
+ * ```
158
+ *
159
+ * # Example showing use of `'cursorLifetime'`
160
+ *
161
+ * ```ts
162
+ * const cursor = collection.find({}, { timeoutMS: 1000, timeoutMode: 'cursorLifetime' });
163
+ * const docs = await cursor.toArray(); // This entire line will throw a timeout error if all batches are not fetched and returned within 1000ms.
164
+ * ```
165
+ */
122
166
timeoutMode ?: CursorTimeoutMode ;
123
167
124
168
/**
0 commit comments