Method TryRunUnderLeaseAsync
- Namespace
- MailFathom.Application.Coordination
- Assembly
- MailFathom.Application.dll
TryRunUnderLeaseAsync(WorkScope, Func<CancellationToken, Task>, CancellationToken)
Takes the lease on a scope, runs the work under it, and gives the lease back once the work ends.
Task<bool> TryRunUnderLeaseAsync(WorkScope scope, Func<CancellationToken, Task> work, CancellationToken cancellationToken)
Parameters
scopeWorkScopeThe unit of work to hold.
workFunc<CancellationToken, Task>The work, handed a token cancelled with
cancellationTokenand when the lease is lost.cancellationTokenCancellationTokenCancels the claim and the work.
Returns
- Task<bool>
true when the work ran under the lease; false when another holder has the scope or the claim could not be made, in which case the work never started.
Remarks
A refusal is not a failure. The work belongs to another holder for now, or the database could not be asked, and in both cases the caller asks again on the interval it would have run on.
Exceptions
- OperationCanceledException
Thrown when
cancellationTokenis cancelled while the lease is asked for.