File tree Expand file tree Collapse file tree 2 files changed +12
-9
lines changed Expand file tree Collapse file tree 2 files changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -642,16 +642,14 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
642
642
}
643
643
644
644
const session = this . startSession ( options ) ;
645
- const PromiseConstructor = PromiseProvider . get ( ) ?? Promise ;
646
-
647
- return PromiseConstructor . resolve ( )
648
- . then ( ( ) => withSessionCallback ( session ) )
649
- . then ( ( ) => {
650
- // Do not return the result of callback
651
- } )
652
- . finally ( ( ) => {
645
+
646
+ return maybeCallback ( async ( ) => {
647
+ try {
648
+ await withSessionCallback ( session ) ;
649
+ } finally {
653
650
session . endSession ( ) . catch ( ( ) => null ) ;
654
- } ) ;
651
+ }
652
+ } , null ) ;
655
653
}
656
654
657
655
/**
Original file line number Diff line number Diff line change @@ -438,9 +438,14 @@ export function* makeCounter(seed = 0): Generator<number> {
438
438
/**
439
439
* Helper for handling legacy callback support.
440
440
*/
441
+ export function maybeCallback < T > ( promiseFn : ( ) => Promise < T > , callback : null ) : Promise < T > ;
441
442
export function maybeCallback < T > (
442
443
promiseFn : ( ) => Promise < T > ,
443
444
callback ?: Callback < T >
445
+ ) : Promise < T > | void ;
446
+ export function maybeCallback < T > (
447
+ promiseFn : ( ) => Promise < T > ,
448
+ callback ?: Callback < T > | null
444
449
) : Promise < T > | void {
445
450
const PromiseConstructor = PromiseProvider . get ( ) ;
446
451
You can’t perform that action at this time.
0 commit comments