< Summary

Information
Class: IceRpc.Internal.TaskExtensions
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Internal/TaskExtensions.cs
Tag: 275_13775359185
Line coverage
81%
Covered lines: 13
Uncovered lines: 3
Coverable lines: 16
Total lines: 34
Line coverage: 81.2%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage
100%
Covered methods: 2
Total methods: 2
Method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AsCancellationToken(...)100%11100%
CancelOnCompleteAsync()100%1.03170%

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Internal/TaskExtensions.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3namespace IceRpc.Internal;
 4
 5internal static class TaskExtensions
 6{
 7    /// <summary>Converts this task into a linked cancellation token.</summary>
 8    /// <param name="task">The task that upon completion cancels the linked token.</param>
 9    /// <param name="token">The source token.</param>
 10    /// <returns>A cancellation token that is canceled when <paramref name="task" /> completes or
 11    /// <paramref name="token" /> is canceled.</returns>
 12    internal static CancellationToken AsCancellationToken(this Task task, CancellationToken token)
 80213    {
 80214        var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(token);
 15
 80216        CancellationToken linkedToken = linkedCts.Token;
 80217        _ = CancelOnCompleteAsync();
 80218        return linkedToken;
 19
 20        async Task CancelOnCompleteAsync()
 80221        {
 80222            using CancellationTokenSource cts = linkedCts; // takes ownership of linkedCts
 23            try
 80224            {
 80225                await task.ConfigureAwait(false);
 80026            }
 027            catch
 028            {
 29                // It's ok for task to complete with an exception.
 030            }
 80031            cts.Cancel();
 80032        }
 80233    }
 34}