< Summary

Information
Class: Elsa.Workflows.Runtime.WorkflowActivationLease
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Services/WorkflowActivationLease.cs
Line coverage
100%
Covered lines: 20
Uncovered lines: 0
Coverable lines: 20
Total lines: 60
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Denied()100%11100%
.ctor(...)100%11100%
.ctor(...)100%11100%
.ctor(...)100%11100%
get_CanStart()100%11100%
GetEffectiveCancellationToken(...)100%22100%
DisposeAsync()100%22100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Services/WorkflowActivationLease.cs

#LineLine coverage
 1namespace Elsa.Workflows.Runtime;
 2
 3/// <summary>
 4/// The result of an activation-gate evaluation. Dispose after the new instance is persisted
 5/// so the uniqueness check becomes visible to waiters.
 6/// </summary>
 7public sealed class WorkflowActivationLease : IAsyncDisposable
 8{
 9    private IAsyncDisposable? _lockHandle;
 10    private CancellationTokenSource? _linkedCancellationTokenSource;
 11    private readonly CancellationToken _effectiveCancellationToken;
 12
 13    /// <summary>
 14    /// A lease that denies activation. No lock is held.
 15    /// </summary>
 1316    public static WorkflowActivationLease Denied { get; } = new(false, null);
 17
 18    public WorkflowActivationLease(bool canStart, IAsyncDisposable? lockHandle)
 419        : this(canStart, lockHandle, CancellationToken.None, null)
 20    {
 421    }
 22
 23    internal WorkflowActivationLease(bool canStart, IAsyncDisposable? lockHandle, CancellationToken effectiveCancellatio
 524        : this(canStart, lockHandle, effectiveCancellationToken, null)
 25    {
 526    }
 27
 18528    internal WorkflowActivationLease(bool canStart, IAsyncDisposable? lockHandle, CancellationToken effectiveCancellatio
 29    {
 18530        CanStart = canStart;
 18531        _lockHandle = lockHandle;
 18532        _effectiveCancellationToken = effectiveCancellationToken;
 18533        _linkedCancellationTokenSource = linkedCancellationTokenSource;
 18534    }
 35
 36    /// <summary>
 37    /// Whether a new workflow instance may be created.
 38    /// </summary>
 18439    public bool CanStart { get; }
 40
 41    internal CancellationToken GetEffectiveCancellationToken(CancellationToken fallbackToken) =>
 17042        _effectiveCancellationToken.CanBeCanceled ? _effectiveCancellationToken : fallbackToken;
 43
 44    /// <inheritdoc />
 45    public async ValueTask DisposeAsync()
 46    {
 19347        var lockHandle = Interlocked.Exchange(ref _lockHandle, null);
 19348        var linkedCancellationTokenSource = Interlocked.Exchange(ref _linkedCancellationTokenSource, null);
 49
 50        try
 51        {
 19352            if (lockHandle != null)
 2653                await lockHandle.DisposeAsync();
 19354        }
 55        finally
 56        {
 19357            linkedCancellationTokenSource?.Dispose();
 58        }
 19359    }
 60}