< Summary

Information
Class: System.Threading.Tasks.TaskCompletionSourceWithCancellation<T>
Assembly: System.Net.Http
File(s): D:\runner\runtime\src\libraries\Common\src\System\Threading\Tasks\TaskCompletionSourceWithCancellation.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 18
Coverable lines: 18
Total lines: 40
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%110%
WaitWithCancellationAsync()0%220%
WaitWithCancellation(...)0%220%
WaitWithCancellationAsync(...)0%220%

File(s)

D:\runner\runtime\src\libraries\Common\src\System\Threading\Tasks\TaskCompletionSourceWithCancellation.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4namespace System.Threading.Tasks
 5{
 6    /// <summary>
 7    /// A <see cref="TaskCompletionSource{TResult}"/> that supports cancellation registration so that any
 8    /// <seealso cref="OperationCanceledException"/>s contain the relevant <see cref="CancellationToken"/>,
 9    /// while also avoiding unnecessary allocations for closure captures.
 10    /// </summary>
 11    internal class TaskCompletionSourceWithCancellation<T> : TaskCompletionSource<T>
 12    {
 013        public TaskCompletionSourceWithCancellation() : base(TaskCreationOptions.RunContinuationsAsynchronously)
 014        {
 015        }
 16
 17        public async ValueTask<T> WaitWithCancellationAsync(CancellationToken cancellationToken)
 018        {
 019            using (cancellationToken.UnsafeRegister(static (s, cancellationToken) => ((TaskCompletionSourceWithCancellat
 020            {
 021                return await Task.ConfigureAwait(false);
 22            }
 023        }
 24
 25        public T WaitWithCancellation(CancellationToken cancellationToken)
 026        {
 027            using (cancellationToken.UnsafeRegister(static (s, cancellationToken) => ((TaskCompletionSourceWithCancellat
 028            {
 029                return Task.GetAwaiter().GetResult();
 30            }
 031        }
 32
 33        public ValueTask<T> WaitWithCancellationAsync(bool async, CancellationToken cancellationToken)
 034        {
 035            return async ?
 036                WaitWithCancellationAsync(cancellationToken) :
 037                new ValueTask<T>(WaitWithCancellation(cancellationToken));
 038        }
 39    }
 40}