-
-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed code that removes item upon TaskCanceledException.
It is not necessary as the request will be simply dequeued when TryGrantNextPendingRequest gets called shortly after.
- Loading branch information
1 parent
a762d76
commit 78760ff
Showing
3 changed files
with
31 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 22 additions & 2 deletions
24
ShopifySharp/Infrastructure/Policies/LeakyBucket/LeakyBucketRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,36 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShopifySharp.Infrastructure.Policies.LeakyBucket; | ||
|
||
internal sealed class LeakyBucketRequest(int cost, CancellationToken cancellationToken) : IDisposable | ||
{ | ||
public readonly int Cost = cost; | ||
public readonly SemaphoreSlim Semaphore = new(0, 1); | ||
|
||
public readonly CancellationToken CancellationToken = cancellationToken; | ||
|
||
public bool IsDisposed { get; private set; } | ||
|
||
private readonly SemaphoreSlim Semaphore = new(0, 1); | ||
|
||
public void Dispose() | ||
{ | ||
Semaphore?.Dispose(); | ||
if (IsDisposed) | ||
return; | ||
|
||
Semaphore.Dispose(); | ||
IsDisposed = true; | ||
} | ||
|
||
public void Release() | ||
{ | ||
if (!IsDisposed) | ||
Semaphore.Release(); | ||
} | ||
|
||
public Task WaitAsync(CancellationToken t) | ||
{ | ||
return Semaphore.WaitAsync(t); | ||
} | ||
} |