Method CommitAsync
- Namespace
- MailFathom.Application.Persistence
- Assembly
- MailFathom.Application.dll
CommitAsync(Func<IPersistenceSession, CancellationToken, Task>, CancellationToken)
Stages and commits a complete local write in a fresh session for every attempt.
public Task CommitAsync(Func<IPersistenceSession, CancellationToken, Task> stageChangesAsync, CancellationToken cancellationToken)
Parameters
stageChangesAsyncFunc<IPersistenceSession, CancellationToken, Task>Stages the complete idempotent local write in the supplied session.
cancellationTokenCancellationTokenCancels session creation, staging, commit, or a subsequent retry.
Returns
- Task
A task that completes once one attempt has committed.
Exceptions
- PersistenceConcurrencyConflictException
Thrown when every allowed attempt conflicted.
- OperationCanceledException
Thrown when the caller cancels before or between attempts.
CommitAsync<TResult>(Func<IPersistenceSession, CancellationToken, Task<TResult>>, CancellationToken)
Stages and commits a complete local write that answers with what it wrote.
public Task<TResult> CommitAsync<TResult>(Func<IPersistenceSession, CancellationToken, Task<TResult>> stageChangesAsync, CancellationToken cancellationToken)
Parameters
stageChangesAsyncFunc<IPersistenceSession, CancellationToken, Task<TResult>>Stages the complete idempotent local write in the supplied session and answers with its result.
cancellationTokenCancellationTokenCancels session creation, staging, commit, or a subsequent retry.
Returns
- Task<TResult>
What the attempt that committed produced.
Type Parameters
TResultWhat the write answers with.
Remarks
The result of an attempt that did not commit is discarded, which is the whole reason this exists rather than a caller assigning to a captured local: a variable written by the losing attempt keeps its value, so code reading it after a conflict would be reading a row that was rolled back.
Exceptions
- PersistenceConcurrencyConflictException
Thrown when every allowed attempt conflicted.
- OperationCanceledException
Thrown when the caller cancels before or between attempts.