< Summary

Information
Class: Elsa.Caching.Services.ChangeTokenSignalInvoker
Assembly: Elsa.Caching
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Caching/Services/ChangeTokenSignalInvoker.cs
Line coverage
100%
Covered lines: 14
Uncovered lines: 0
Coverable lines: 14
Total lines: 38
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
GetToken(...)100%11100%
TriggerTokenAsync(...)100%22100%
get_ChangeToken()100%11100%
get_TokenSource()100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Caching/Services/ChangeTokenSignalInvoker.cs

#LineLine coverage
 1using System.Collections.Concurrent;
 2using Microsoft.Extensions.Primitives;
 3
 4namespace Elsa.Caching.Services;
 5
 6/// <inheritdoc />
 7public class ChangeTokenSignalInvoker : IChangeTokenSignalInvoker
 8{
 19    private readonly ConcurrentDictionary<string, ChangeTokenInfo> _changeTokens = new();
 10
 11    /// <inheritdoc />
 12    public IChangeToken GetToken(string key)
 13    {
 371414        return _changeTokens.GetOrAdd(
 371415            key,
 371416            _ =>
 371417            {
 121118                var cancellationTokenSource = new CancellationTokenSource();
 121119                var changeToken = new CancellationChangeToken(cancellationTokenSource.Token);
 121120                return new ChangeTokenInfo(changeToken, cancellationTokenSource);
 371421            }).ChangeToken;
 22    }
 23
 24    /// <inheritdoc />
 25    public ValueTask TriggerTokenAsync(string key, CancellationToken cancellationToken = default)
 26    {
 267327        if (_changeTokens.TryRemove(key, out var changeTokenInfo))
 119328            changeTokenInfo.TokenSource.Cancel();
 29
 267330        return default;
 31    }
 32
 33    private readonly struct ChangeTokenInfo(IChangeToken changeToken, CancellationTokenSource tokenSource)
 34    {
 492535        public IChangeToken ChangeToken { get; } = changeToken;
 240436        public CancellationTokenSource TokenSource { get; } = tokenSource;
 37    }
 38}