Skip to content

Commit 868264d

Browse files
committed
Make client disposable so it clears Grpc clients
1 parent 6722ced commit 868264d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/xAI/GrokClient.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ namespace xAI;
77
/// <summary>Client for interacting with the Grok service.</summary>
88
/// <param name="apiKey">The API key used for authentication.</param>
99
/// <param name="options">The options used to configure the client.</param>
10-
public class GrokClient(string apiKey, GrokClientOptions options)
10+
public sealed class GrokClient(string apiKey, GrokClientOptions options) : IDisposable
1111
{
12-
static ConcurrentDictionary<(Uri, string), GrpcChannel> channels = [];
12+
static readonly ConcurrentDictionary<(Uri, string), GrpcChannel> channels = [];
1313

1414
/// <summary>Initializes a new instance of the <see cref="GrokClient"/> class with default options.</summary>
1515
public GrokClient(string apiKey) : this(apiKey, new GrokClientOptions()) { }
@@ -36,6 +36,9 @@ public class GrokClient(string apiKey, GrokClientOptions options)
3636
return GrpcChannel.ForAddress(Endpoint, options);
3737
});
3838

39+
/// <summary>Clears the cached list of gRPC channels in the client.</summary>
40+
public void Dispose() => channels.Clear();
41+
3942
class AuthenticationHeaderHandler(string apiKey) : DelegatingHandler
4043
{
4144
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)

0 commit comments

Comments
 (0)