Expose SemaphoreSlim.Acquire with CancellationToken

This commit is contained in:
2025-05-20 12:25:36 +02:00
parent bae28b2552
commit af1dfd6751
4 changed files with 14 additions and 3 deletions
@@ -8,7 +8,7 @@
<RootNamespace>System</RootNamespace>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Version>1.6.11</Version>
<Version>1.6.12</Version>
<Authors>Alexandru Macocian</Authors>
<RepositoryUrl>https://github.com/AlexMacocian/SystemExtensions</RepositoryUrl>
<Description>Extensions for the System namespace</Description>
@@ -8,4 +8,9 @@ public static class SemaphoreSlimExtensions
{
return await SemaphoreSlimContext.Create(semaphore);
}
public static async Task<SemaphoreSlimContext> Acquire(this SemaphoreSlim semaphore, CancellationToken cancellationToken)
{
return await SemaphoreSlimContext.Create(semaphore, cancellationToken);
}
}
@@ -2,12 +2,12 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<RootNamespace>System</RootNamespace>
<Version>1.6.11</Version>
<Version>1.6.12</Version>
<Authors>Alexandru Macocian</Authors>
<RepositoryUrl>https://github.com/AlexMacocian/SystemExtensions</RepositoryUrl>
<Description>Extensions for the System namespace</Description>
@@ -21,4 +21,10 @@ public readonly struct SemaphoreSlimContext : IDisposable
await semaphore.ThrowIfNull(nameof(semaphore)).WaitAsync();
return new SemaphoreSlimContext(semaphore);
}
public static async Task<SemaphoreSlimContext> Create(SemaphoreSlim semaphore, CancellationToken cancellationToken)
{
await semaphore.ThrowIfNull(nameof(semaphore)).WaitAsync(cancellationToken);
return new SemaphoreSlimContext(semaphore);
}
}