Method CommitAsync
CommitAsync(CancellationToken)
Commits the staged transaction, making the files it added and deleted permanent in the repository. Call this after the application's database has committed.
Declaration
public Task CommitAsync(CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancellationToken | A cancellation token that cancels the call while it waits for another call on the transaction to finish. Once the commit has started it is not observed. |
Returns
| Type | Description |
|---|---|
| Task |
Implements
Remarks
The transaction's journal is committed first, by renaming it, which is a single atomic operation however many files it lists. The added files are committed next, and then the deletions are applied according to DeleteMode: in Immediate mode the files are deleted now and the journal is removed; in the deferred modes the committed journal stays as the delete record of its files, and a cleanup pass deletes them once it is older than the delete delay.
A failure to commit the journal is thrown; nothing else has been committed in that case and the call can be retried. Failures to commit or delete individual files are not thrown: they are reported through TransactionCompletionFailed, as for an ordinary transaction, and the affected files are left for the cleaner. Calling this method again after it succeeded does nothing.
Once this method has started the commit, the transaction is never rolled back, whatever the method throws. If it is not called again, disposing the transaction leaves the files to the cleaner. After a failure to commit the journal, that depends on how far the step came: if the rename failed, the journal is still staged, and the cleaner resolves its files through the resolution callback; if the journal was renamed and could not be flushed to disk, it is committed although the call threw, and the cleaner deletes its files without asking. The added files are resolved through the callback in both cases. An exception thrown by a TransactionCompletionFailed handler propagates once the transaction is committed.
An OperationCanceledException is thrown before the commit has started: the transaction is still staged, and disposing it rolls it back. Pass None here, since the application's database has committed.
On a version 1 repository, which has no journal (see FileRepoStagedTransaction), the added files are committed first and then each deletion is committed as by CommitAsync(CancellationToken); every failure is reported rather than thrown.
Exceptions
| Type | Condition |
|---|---|
| IOException | The journal could not be committed. |
| OperationCanceledException | The token was cancelled before the commit had started. Nothing has been committed. |
| InvalidOperationException | The transaction has been rolled back. |
| ObjectDisposedException | The transaction was disposed before the stage was committed. |