< Summary

Information
Class: IceRpc.Internal.TaskExtensions
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Internal/TaskExtensions.cs
Tag: 276_17717543480
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)
 80413    {
 80414        var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(token);
 15
 80416        CancellationToken linkedToken = linkedCts.Token;
 80417        _ = CancelOnCompleteAsync();
 80418        return linkedToken;
 19
 20        async Task CancelOnCompleteAsync()
 80421        {
 80422            using CancellationTokenSource cts = linkedCts; // takes ownership of linkedCts
 23            try
 80424            {
 80425                await task.ConfigureAwait(false);
 80226            }
 027            catch
 028            {
 29                // It's ok for task to complete with an exception.
 030            }
 80231            cts.Cancel();
 80232        }
 80433    }
 34}