2024-10-25 14:33:26 -04:00
|
|
|
// Copyright (C) 2024 Intro-Skipper contributors <intro-skipper.org>
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-only.
|
2024-10-25 13:42:34 -04:00
|
|
|
|
2024-04-16 18:19:05 +02:00
|
|
|
using System;
|
|
|
|
using System.Threading;
|
|
|
|
|
2024-10-20 13:56:09 +02:00
|
|
|
namespace IntroSkipper.ScheduledTasks;
|
2024-04-16 18:19:05 +02:00
|
|
|
|
|
|
|
internal sealed class ScheduledTaskSemaphore : IDisposable
|
|
|
|
{
|
2024-09-10 18:08:42 +02:00
|
|
|
private static readonly SemaphoreSlim _semaphore = new(1, 1);
|
2024-04-16 18:19:05 +02:00
|
|
|
|
|
|
|
private ScheduledTaskSemaphore()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-09-23 19:45:16 +02:00
|
|
|
public static IDisposable Acquire(CancellationToken cancellationToken)
|
2024-04-16 18:19:05 +02:00
|
|
|
{
|
2024-09-23 19:45:16 +02:00
|
|
|
_semaphore.Wait(cancellationToken);
|
2024-05-10 06:35:52 +02:00
|
|
|
return new ScheduledTaskSemaphore();
|
2024-04-16 18:19:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
2024-09-23 19:45:16 +02:00
|
|
|
_semaphore.Release();
|
2024-04-16 18:19:05 +02:00
|
|
|
}
|
|
|
|
}
|