Skip to content

Commit

Permalink
Revert "Using a fifo semaphore to ensure that requests are granted ac…
Browse files Browse the repository at this point in the history
…cess to the API in fifo order."

This reverts commit 32758ff.
  • Loading branch information
clement911 committed Feb 19, 2024
1 parent 32758ff commit f5d1a9c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 40 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
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 f5d1a9c

Please sign in to comment.