Method TryDeleteAsync
TryDeleteAsync(FileId, CancellationToken)
Deletes an existing or tentatively added file from the repository by its file ID if it exists, and reports whether it did.
Declaration
public Task<bool> TryDeleteAsync(FileId fileId, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| FileId | fileId | The ID of the file to delete. |
| CancellationToken | cancellationToken | A cancellation token that cancels the operation. |
Returns
| Type | Description |
|---|---|
| Task<bool> | true if the file existed and its deletion is now recorded by this transaction (or was added by this transaction and has been discarded); false if no such file exists. |
Implements
Remarks
This is the idempotent form of DeleteAsync(FileId, CancellationToken) for callers that are retrying or replaying work that may already have run. Nothing is recorded when false is returned.
A file that another transaction has deleted exists until its deletion has been carried out, so this method returns true for a file whose deletion has committed and is pending cleanup, and the deletions converge as described on DeleteAsync(FileId, CancellationToken).
Prefer DeleteAsync(FileId, CancellationToken) when the application believes the file exists: a file that is unexpectedly missing usually indicates an application bug or a missing referenced file, and it should surface rather than be ignored.
A file that another transaction has added and not committed yet exists, so this method returns true for it, and its deletion is handled as described on DeleteAsync(FileId, CancellationToken).
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | The transaction has been staged or rolled back. |