Documentation / @andrew_l/mongo-transaction / onCommitted
Function: onCommitted()
onCommitted(
callback,dependencies?):Fn$1
Registers a callback that runs once after a successful commit, regardless of retries. A hook error is logged and does not affect the transaction result.
Parameters
callback
OnCommittedCallback
Runs after the commit.
dependencies?
readonly any[]
When provided, the callback is replaced on retry only if they changed.
Returns
Fn$1
Cancels the callback.
Examples
ts
// Basic usage without dependencies
onCommitted(() => {
console.log('Transaction committed!');
});ts
// Using dependencies
count++;
onCommitted(() => {
console.log(`Commit #${count}`);
}, [count]);ts
// Cancel by request
const cancel = onCommitted(() => {
console.log('This will run only once!');
});
if (orderReceived) {
cancel(); // Prevents onCommitted from running
}