| 386 | } |
| 387 | |
| 388 | override async transactional<T>( |
| 389 | cb: (trx: Transaction<ClientSession>) => Promise<T>, |
| 390 | options: { |
| 391 | isolationLevel?: IsolationLevel; |
| 392 | ctx?: Transaction<ClientSession>; |
| 393 | eventBroadcaster?: TransactionEventBroadcaster; |
| 394 | } & TransactionOptions = {}, |
| 395 | ): Promise<T> { |
| 396 | await this.ensureConnection(); |
| 397 | const session = await this.begin(options); |
| 398 | |
| 399 | try { |
| 400 | const ret = await cb(session); |
| 401 | await this.commit(session, options.eventBroadcaster); |
| 402 | |
| 403 | return ret; |
| 404 | } catch (error) { |
| 405 | await this.rollback(session, options.eventBroadcaster); |
| 406 | throw error; |
| 407 | } finally { |
| 408 | await session.endSession(); |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | override async begin( |
| 413 | options: { |