Method StageAsync
StageAsync(CancellationToken)
Stages the transaction: makes the deletions it recorded durable and returns the stage that commits the transaction. Call this before committing the application's database, and commit the stage after.
Declaration
Task<IFileRepoStage> StageAsync(CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancellationToken | A cancellation token that cancels the call before the transaction has been staged. Once it is staged, the call is not interrupted. |
Returns
| Type | Description |
|---|---|
| Task<IFileRepoStage> | The stage that commits the transaction. |
Remarks
Once the transaction is staged, files can no longer be added to it or deleted by it.
A failure to stage is thrown, and so is a cancellation. Nothing has been staged in that case and the transaction is as it was before the call: it can be staged again or rolled back, and the application must not commit its database. Disposing it then records nothing for its deletions and leaves the files it added indeterminate (see IFileRepoStagedTransaction); roll it back first to discard them at once.
An implementation that does not accept the deletion of a file that another transaction is adding, and finds that out when it stages, may wait briefly for that transaction to finish before it throws a RepoFileBusyException (see DeleteAsync(FileId, CancellationToken)). Nothing has been staged then either, and the transaction can be staged again once the adding transaction has finished.
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | The transaction has already been staged, or it has been rolled back. |
| RepoFileBusyException | One of the deletions is of a file that another transaction is adding and has not finished, which the implementation does not accept (see DeleteAsync(FileId, CancellationToken)). Nothing has been staged. |
| IOException | The deletions could not be made durable. |
| OperationCanceledException | The token was cancelled before the transaction had been staged. Nothing has been staged. |
| ObjectDisposedException | The transaction has been disposed. |