rlauuzo 60c735282e
apply auto-fixes from VS Code (#283)
Co-authored-by: rlauu <46294892+rlauu@users.noreply.github.com>
2024-09-10 18:08:42 +02:00

36 lines
815 B
C#

using System;
using System.Threading;
namespace ConfusedPolarBear.Plugin.IntroSkipper.ScheduledTasks;
internal sealed class ScheduledTaskSemaphore : IDisposable
{
private static readonly SemaphoreSlim _semaphore = new(1, 1);
private static bool _isHeld;
private ScheduledTaskSemaphore()
{
}
public static int CurrentCount => _semaphore.CurrentCount;
public static IDisposable Acquire(int timeout, CancellationToken cancellationToken)
{
_isHeld = _semaphore.Wait(timeout, cancellationToken);
return new ScheduledTaskSemaphore();
}
/// <summary>
/// Dispose.
/// </summary>
public void Dispose()
{
if (_isHeld) // Release only if acquired
{
_semaphore.Release();
_isHeld = false;
}
}
}