< Summary

Information
Class: IceRpc.Internal.TaskExtensions
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Internal/TaskExtensions.cs
Tag: 1856_27024993493
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
Fully covered methods: 0
Total methods: 2
Method coverage: 100%
Full method coverage: 0%

Metrics

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

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)
 44213    {
 44214        var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(token);
 15
 44216        CancellationToken linkedToken = linkedCts.Token;
 44217        _ = CancelOnCompleteAsync();
 44218        return linkedToken;
 19
 20        async Task CancelOnCompleteAsync()
 44221        {
 44222            using CancellationTokenSource cts = linkedCts; // takes ownership of linkedCts
 23            try
 44224            {
 44225                await task.ConfigureAwait(false);
 44126            }
 027            catch
 028            {
 29                // It's ok for task to complete with an exception.
 030            }
 44131            cts.Cancel();
 44132        }
 44233    }
 34}