< Summary

Information
Class: IceRpc.Internal.SemaphoreLock
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Internal/SemaphoreSlimExtensions.cs
Tag: 275_13775359185
Line coverage
100%
Covered lines: 2
Uncovered lines: 0
Coverable lines: 2
Total lines: 40
Line coverage: 100%
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
Dispose()100%11100%
.ctor(...)100%11100%

File(s)

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

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3namespace IceRpc.Internal;
 4
 5internal static class SemaphoreSlimExtensions
 6{
 7    /// <summary>Acquires a semaphore lock. The acquisition waits to enter the semaphore and returns a lock that will
 8    /// release the semaphore when disposed.</summary>
 9    /// <param name="semaphore">The semaphore.</param>
 10    /// <returns>The semaphore lock.</returns>
 11    internal static SemaphoreLock Acquire(this SemaphoreSlim semaphore)
 12    {
 13        semaphore.Wait();
 14        return new SemaphoreLock(semaphore);
 15    }
 16
 17    /// <summary>Acquires a semaphore lock. The acquisition waits to enter the semaphore and returns a lock that will
 18    /// release the semaphore when disposed.</summary>
 19    /// <param name="semaphore">The semaphore.</param>
 20    /// <param name="cancellationToken">A cancellation token that receives the cancellation requests.</param>
 21    /// <returns>The semaphore lock.</returns>
 22    internal static async ValueTask<SemaphoreLock> AcquireAsync(
 23        this SemaphoreSlim semaphore,
 24        CancellationToken cancellationToken)
 25    {
 26        await semaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
 27        return new SemaphoreLock(semaphore);
 28    }
 29}
 30
 31/// <summary>A simple helper for releasing a semaphore.</summary>
 32/// <remarks>The caller must be extremely careful to call Dispose at most once.</remarks>
 33internal readonly struct SemaphoreLock : IDisposable
 34{
 35    private readonly SemaphoreSlim _semaphore;
 36
 563837    public void Dispose() => _semaphore.Release();
 38
 563839    internal SemaphoreLock(SemaphoreSlim semaphore) => _semaphore = semaphore;
 40}