Skip to content

Commit

Permalink
Merge pull request #1021 from clement911/master
Browse files Browse the repository at this point in the history
Revert "Using a fifo semaphore to ensure that requests are granted ac…
  • Loading branch information
clement911 committed Feb 19, 2024
2 parents c693018 + f5d1a9c commit 924fbab
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 40 deletions.

This file was deleted.

Expand Up @@ -9,7 +9,7 @@ internal class LeakyBucket
private class Request
{
public int cost;
public FifoSemaphore fifoSemaphore = new FifoSemaphore(0, 1);
public SemaphoreSlim semaphore = new SemaphoreSlim(0, 1);
public CancellationToken cancelToken;

public Request(int cost, CancellationToken cancelToken)
Expand Down Expand Up @@ -109,7 +109,7 @@ public async Task WaitForAvailableAsync(int requestCost, CancellationToken cance
if (_waitingRequests.Count == 1)
ScheduleTryGrantNextPendingRequest(r);
}
await r.fifoSemaphore.WaitAsync(cancellationToken);
await r.semaphore.WaitAsync(cancellationToken);
}

private void ScheduleTryGrantNextPendingRequest(Request r)
Expand All @@ -132,7 +132,7 @@ private void TryGrantNextPendingRequest()
var r = _waitingRequests.Dequeue();
if (!r.cancelToken.IsCancellationRequested)
{
r.fifoSemaphore.Release();
r.semaphore.Release();
ConsumeAvailable(r);
}
}
Expand Down

0 comments on commit 924fbab

Please sign in to comment.