Skip to content

Commit dbca0b5

Browse files
committed
fix: Make LeakyBucketRequest disposable and dispose its SemaphoreSlim
1 parent a5b7154 commit dbca0b5

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

ShopifySharp/Infrastructure/Policies/LeakyBucketPolicy/LeakyBucket.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public async Task WaitForAvailableAsync(int requestCost, CancellationToken cance
8181
if (requestCost > MaximumAvailable)
8282
throw new ShopifyException($"Requested query cost of {requestCost} is larger than maximum available {MaximumAvailable}");
8383

84-
var r = new LeakyBucketRequest(requestCost, cancellationToken);
84+
using var r = new LeakyBucketRequest(requestCost, cancellationToken);
8585

8686
lock (_lock)
8787
{
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1+
using System;
12
using System.Threading;
23

34
namespace ShopifySharp.Infrastructure.Policies.LeakyBucketPolicy;
45

5-
internal sealed class LeakyBucketRequest(int cost, CancellationToken cancellationToken)
6+
internal sealed class LeakyBucketRequest(int cost, CancellationToken cancellationToken) : IDisposable
67
{
78
public readonly int Cost = cost;
89
public readonly SemaphoreSlim Semaphore = new(0, 1);
910
public readonly CancellationToken CancellationToken = cancellationToken;
11+
12+
public void Dispose()
13+
{
14+
Semaphore?.Dispose();
15+
}
1016
}

0 commit comments

Comments
 (0)