Method TrySpendAsync
- Namespace
- MailFathom.Application.Access.Credentials
- Assembly
- MailFathom.Application.dll
TrySpendAsync(string, string, DateTimeOffset, CancellationToken)
Spends one identifier against the credential that verified the assertion carrying it.
Task<bool> TrySpendAsync(string credentialKey, string identifier, DateTimeOffset expiresAt, CancellationToken cancellationToken)
Parameters
credentialKeystringWhat identifies the verifying credential, which scopes the identifier to it.
identifierstringThe assertion's own replay identifier.
expiresAtDateTimeOffsetWhen the assertion stops being accepted, which is when the record stops being needed.
cancellationTokenCancellationTokenCancels the write.
Returns
- Task<bool>
true when this call is the one that spent the identifier; false when something already had.
Remarks
One statement whose own outcome is the answer, so two replicas presenting one identifier at the same instant leave one served and one refused with PostgreSQL settling it rather than a check between two statements. An implementation that read and then wrote would admit both.
Exceptions
- ClientAssertionSpendUnrecordableException
Thrown when the record could not be written, which the caller answers by refusing rather than by serving.