Table of Contents

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

scope WorkScope

The unit of work to hold.

work Func<CancellationToken, Task>

The work, handed a token cancelled with cancellationToken and when the lease is lost.

cancellationToken CancellationToken

Cancels 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 cancellationToken is cancelled while the lease is asked for.