@@ -51,6 +51,35 @@ export interface UnifiedChangeStream extends ChangeStream {
51
51
eventCollector : InstanceType < typeof import ( '../../tools/utils' ) [ 'EventCollector' ] > ;
52
52
}
53
53
54
+ export class UnifiedThread {
55
+ #promise: Promise < void > ;
56
+ #error: Error ;
57
+ #killed = false ;
58
+
59
+ id : string ;
60
+
61
+ constructor ( id ) {
62
+ this . id = id ;
63
+ this . #promise = Promise . resolve ( ) ;
64
+ }
65
+
66
+ queue ( functionToQueue : ( ) => Promise < any > ) {
67
+ if ( this . #killed || this . #error) {
68
+ return ;
69
+ }
70
+
71
+ this . #promise = this . #promise. then ( functionToQueue ) . catch ( e => ( this . #error = e ) ) ;
72
+ }
73
+
74
+ async finish ( ) {
75
+ this . #killed = true ;
76
+ await this . #promise;
77
+ if ( this . #error) {
78
+ throw this . #error;
79
+ }
80
+ }
81
+ }
82
+
54
83
export type CommandEvent = CommandStartedEvent | CommandSucceededEvent | CommandFailedEvent ;
55
84
export type CmapEvent =
56
85
| ConnectionPoolCreatedEvent
@@ -285,6 +314,7 @@ export type EntityCtor =
285
314
| typeof ChangeStream
286
315
| typeof AbstractCursor
287
316
| typeof GridFSBucket
317
+ | typeof UnifiedThread
288
318
| ClientEncryption ;
289
319
290
320
export type EntityTypeId =
@@ -293,6 +323,7 @@ export type EntityTypeId =
293
323
| 'collection'
294
324
| 'session'
295
325
| 'bucket'
326
+ | 'thread'
296
327
| 'cursor'
297
328
| 'stream'
298
329
| 'clientEncryption' ;
@@ -303,6 +334,7 @@ ENTITY_CTORS.set('db', Db);
303
334
ENTITY_CTORS . set ( 'collection' , Collection ) ;
304
335
ENTITY_CTORS . set ( 'session' , ClientSession ) ;
305
336
ENTITY_CTORS . set ( 'bucket' , GridFSBucket ) ;
337
+ ENTITY_CTORS . set ( 'thread' , UnifiedThread ) ;
306
338
ENTITY_CTORS . set ( 'cursor' , AbstractCursor ) ;
307
339
ENTITY_CTORS . set ( 'stream' , ChangeStream ) ;
308
340
@@ -335,6 +367,7 @@ export class EntitiesMap<E = Entity> extends Map<string, E> {
335
367
getEntity ( type : 'collection' , key : string , assertExists ?: boolean ) : Collection ;
336
368
getEntity ( type : 'session' , key : string , assertExists ?: boolean ) : ClientSession ;
337
369
getEntity ( type : 'bucket' , key : string , assertExists ?: boolean ) : GridFSBucket ;
370
+ getEntity ( type : 'thread' , key : string , assertExists ?: boolean ) : UnifiedThread ;
338
371
getEntity ( type : 'cursor' , key : string , assertExists ?: boolean ) : AbstractCursor ;
339
372
getEntity ( type : 'stream' , key : string , assertExists ?: boolean ) : UnifiedChangeStream ;
340
373
getEntity ( type : 'clientEncryption' , key : string , assertExists ?: boolean ) : ClientEncryption ;
@@ -474,6 +507,8 @@ export class EntitiesMap<E = Entity> extends Map<string, E> {
474
507
}
475
508
476
509
map . set ( entity . bucket . id , new GridFSBucket ( db , options ) ) ;
510
+ } else if ( 'thread' in entity ) {
511
+ map . set ( entity . thread . id , new UnifiedThread ( entity . thread . id ) ) ;
477
512
} else if ( 'stream' in entity ) {
478
513
throw new Error ( `Unsupported Entity ${ JSON . stringify ( entity ) } ` ) ;
479
514
} else if ( 'clientEncryption' in entity ) {
0 commit comments