Iceshrimp.NET/Iceshrimp.Backend/Core/Helpers/SemaphorePlus.cs
Laura Hausmann a845405c45
[backend/queue] Fix QueueService race condition (properly this time)
While the previous fix was likely enough, there was still a razor-thin theoretical race condition remaining. This commit fixes said race condition, and simplifies some if statements across the file.
2024-07-25 01:29:32 +02:00

13 lines
No EOL
340 B
C#

namespace Iceshrimp.Backend.Core.Helpers;
public class SemaphorePlus(int maxCount) : SemaphoreSlim(maxCount, maxCount)
{
private readonly int _maxCount = maxCount;
public int ActiveCount => _maxCount - CurrentCount;
public async Task WaitAndReleaseAsync(CancellationToken token)
{
await WaitAsync(token);
Release();
}
}