Documentation / @andrew_l/mongo-transaction / onMongoSessionCommitted
Function: onMongoSessionCommitted()
onMongoSessionCommitted(fn)
onMongoSessionCommitted<
T
>(fn
):OnMongoSessionCommittedResult
<T
>
Executes the provided function upon transaction commit.
Returns T
if the transaction is committed and the function completes successfully.
Returns false
if the transaction ends without committing.
Rejects if the function throws an error.
Type Parameters
• T
Parameters
• fn
Returns
OnMongoSessionCommittedResult
<T
>
Example
ts
const { promise } = onTransactionCommitted(async () => {
console.info('Transaction committed successfully!');
return Math.random(); // Random value generated after commit
});
promise.then(result => {
if (result !== false) {
console.info('Handler result:', result); // e.g., Handler result: 0.07576196837476501
}
});
onMongoSessionCommitted(session, fn)
onMongoSessionCommitted<
T
>(session
,fn
):OnMongoSessionCommittedResult
<T
>
Type Parameters
• T
Parameters
• session: ClientSession
• fn