intro-skipper/IntroSkipper/ScheduledTasks/ScheduledTaskSemaphore.cs

29 lines
696 B
C#
Raw Normal View History

2024-10-25 14:31:50 -04:00
// Copyright (C) 2024 Intro-Skipper contributors <intro-skipper.org>
// SPDX-License-Identifier: GPL-3.0-only.
2024-10-25 14:15:12 -04:00
using System;
using System.Threading;
using System.Threading.Tasks;
namespace IntroSkipper.ScheduledTasks;
internal sealed class ScheduledTaskSemaphore : IDisposable
{
private static readonly SemaphoreSlim _semaphore = new(1, 1);
private ScheduledTaskSemaphore()
{
}
public static async Task<IDisposable> AcquireAsync(CancellationToken cancellationToken)
{
await _semaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
2024-05-10 06:35:52 +02:00
return new ScheduledTaskSemaphore();
}
public void Dispose()
{
2024-09-23 19:45:16 +02:00
_semaphore.Release();
}
}